By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Stuck on quotes again

Claus Mygind
P: 571
I asked this question before in a slightly different context, but now it has come back to haunt me again.

I am writing a table of records on the fly. One of the elements I am putting into the table is a link which the user can click to start an ajax request to retrieve a specific record from the server. I want to use this function with several tables so one of the parameters I wanted to pass with the "onClick" event handler was the table name in this case "job".

I just can't seem to figure out how to code the onClick line? My outer wrapper is the ' single quote. The inner wrapper is the " double quote. How can the code below be re-written to incorporate the variable cTable?

Expand|Select|Wrap|Line Numbers
  1. var cTable = "job"
  2. td.innerHTML =    '<a    href="#" '+
  3.             'id="psSelect" '+
  4.             'name="'+encodeURI( object['JOBID'] )+'" '+ 
  5.             'title="Select this record" '+  
  6.             'onClick="psRequestData(this, '+cTable+'); return false;" '+
  7.             '>'+
  8.             object['JOBID'] +
  9.             '</a>&nbsp;&nbsp;' +
Jun 16 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,654
The code you have written would generate HTML as:
[html]<a href="#" id="psSelect" name="JOBID" title="Select this record" onClick="psRequestData(this, job); return false;" >[/html]

And here, we end up passing job to the function instead of 'job' (as a string).

So try this: \''+cTable+'\'

Also instead of concating the HTML again and again, you can let it be a single string.
Jun 16 '08 #2

Claus Mygind
P: 571
Thanks you very much for the solution. Of course it worked as expected. I break the lines up for my own readability but I expect it slows program execution.
Jun 16 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.