Atrag
Atrag

Reputation: 753

OnClick: Passing String as Parameter

I would like to pass a string as a parameter of the following:

<div id="menubutton1" class="menubutton lightbox" onclick="lightbox(1000, 410, hello)">

How would I make "hello" become a parameter. The integers pass without problem.

Thank you.

Upvotes: 1

Views: 3851

Answers (4)

Dan F
Dan F

Reputation: 85

Use single quotes around your string like so:

<div id="menubutton1" class="menubutton lightbox" onclick="lightbox(1000, 410, 'hello')">

Upvotes: 2

Firemen26
Firemen26

Reputation: 1055

You have to add quotes to the string parameter:

<div id="menubutton1" class="menubutton lightbox" onclick="lightbox(1000, 410, 'hello')">

will work.

Upvotes: 1

SungJin Steve Yoo
SungJin Steve Yoo

Reputation: 386

The content of the onclick property is handled as Javascript

<div onclick="HERE IS JAVASCRIPT"></div>

So you should use 'hello' while you are using double quote for onclick property,

or "hello" else using single quote.

Should either use one of it to represent that hello is a string, not a variable name.

Upvotes: 0

Flocke
Flocke

Reputation: 834

Add a ' before hello and a ' after hello: onclick="lightbox(1000, 410, 'hello')"

Upvotes: 1

Related Questions