Connecting Tech Pros Worldwide Forums | Help | Site Map

Escape sequence help Javascript innerHTML

Member
 
Join Date: May 2007
Posts: 63
#1: Jun 22 '07
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 :-)

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Jun 22 '07

re: Escape sequence help Javascript innerHTML


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.
Member
 
Join Date: May 2007
Posts: 63
#3: Jun 26 '07

re: Escape sequence help Javascript innerHTML


Quote:

Originally Posted by acoder

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.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Jun 27 '07

re: Escape sequence help Javascript innerHTML


You're welcome. Glad you got it working.
Reply


Similar JavaScript / Ajax / DHTML bytes