Working with quotes and escape sequences

J

JehanNYNJ

I have to put some html into a variable like so....

var html = '<TABLE cellspacing="5" border="0" .......

But within this html string I also need to have the code for a button
that traps the onclick method like so...

....<input type="button" name="Add Question" value="Repeat Question"
onclick="javascript:getQuestion( '3925','38497', '1' )" >....';

The problem is I am using double quotes for the onclick event and
single quotes for the variables. But I can not use single quotes becuz
the entire html variable is also under single quotes.

I am not sure how I can use escape sequences to help me here. Does
anyone have any suggestions?
 
R

RobB

I have to put some html into a variable like so....

var html = '<TABLE cellspacing="5" border="0" .......

But within this html string I also need to have the code for a button
that traps the onclick method like so...

...<input type="button" name="Add Question" value="Repeat Question"
onclick="javascript:getQuestion( '3925','38497', '1' )" >....';

The problem is I am using double quotes for the onclick event and
single quotes for the variables. But I can not use single quotes becuz
the entire html variable is also under single quotes.

I am not sure how I can use escape sequences to help me here. Does
anyone have any suggestions?

'onclick="getQuestion(\'3925\',\'38497\', \'1\')" >';

Those are integers, you could just pass them as such.

'traps the onclick method' is inventive, but what you're doing is
registering an event handling function, assigning it to the onclick
property of that button. You can lose the javascript: (pseudo-)protocol
as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top