Escape sequence help Javascript innerHTML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tarik Monem
    New Member
    • May 2007
    • 63

    Escape sequence help Javascript innerHTML

    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:

    Code:
    		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>';
    From the preview, it appears as though there is gap between "some" and "NumberComi ng", but there isn't.

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

    Code:
    "myCastDetails('0','document.getElementById('castname0').value','getElementById('casttext0').value','getElementById('castframecolor0').value','getElementById('castpicture0').value');"
    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:

    Code:
    "myCastDetails('0','document.getElementById("castname0").value','getElementById("casttext0").value','getElementById("castframecolor0").value','getElementById("castpicture0").value');"
    Any help would be appreciated and thanks in advance :-)
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

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

    Comment

    • Tarik Monem
      New Member
      • May 2007
      • 63

      #3
      Originally posted by acoder
      To avoid all this, just put the function call into another function (all the stuff in the href from "javascript:cas tDetails(...". 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.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You're welcome. Glad you got it working.

        Comment

        Working...