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

Escape sequence help Javascript innerHTML

P: 63
Just the other day, I received help from this forum on escape sequences with some PHP code which would echo a Javascript onclick.

After the reply helped me, I asked him to explain why it worked and he gave me a URL explaining escape sequences. I thought I understood the tutorial, but I guess I do not.

The closest that I have come to making this work, is the following code:

Expand|Select|Wrap|Line Numbers
  1.  
  2.         myDiv.innerHTML += '<td><a href=\"javascript:myCastDetails(\''+(someNumberComing-1)+'\',\'document.getElementById(\'castname'+(someNumberComing-1)+'\').value\',\'document.getElementById(\'casttext'+(someNumberComing-1)+'\').value\',\'document.getElementById(\'castframecolor'+(someNumberComing-1)+'\').value\',\'document.getElementById(\'castpicture'+(someNumberComing-1)+'\').value\');\"><div>Previous</a></td><td align=right><a href="#">Next</a></div></td>';
  3.  
  4.  
From the preview, it appears as though there is gap between "some" and "NumberComing", but there isn't.

When you place your mouse over the link generated the output at the bottom of the browser is this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. "myCastDetails('0','document.getElementById('castname0').value','getElementById('casttext0').value','getElementById('castframecolor0').value','getElementById('castpicture0').value');"
  3.  
  4.  
Once more, there appears to be a space between "cast" and "name" but there isn't -- apparently I cannot even post correctly :-(

I would like it to be this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. "myCastDetails('0','document.getElementById("castname0").value','getElementById("casttext0").value','getElementById("castframecolor0").value','getElementById("castpicture0").value');"
  3.  
  4.  
  5.  
Any help would be appreciated and thanks in advance :-)
Jun 22 '07 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
To avoid all this, just put the function call into another function (all the stuff in the href from "javascript:castDetails(...". Then just call that. Saves messing with escaped singe and double quotes.
Jun 22 '07 #2

P: 63
To avoid all this, just put the function call into another function (all the stuff in the href from "javascript:castDetails(...". Then just call that. Saves messing with escaped singe and double quotes.

You were absolutely correct. All what I truly needed to pass was what number and within the function that I was calling, I had all the elements waiting for a number so as to choose the correct element, which had I created hidden fields in a step before sending the number.

Thank you for help.
Jun 26 '07 #3

acoder
Expert Mod 15k+
P: 16,027
You're welcome. Glad you got it working.
Jun 27 '07 #4

Post your reply

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