Results 1 to 5 of 5

Thread: echo double quotes for javascript

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default echo double quotes for javascript

    i have to echo out a line :
    Code:
    echo "<td valign='top' align='right' height='38'><a class='textBlockClick1' href='javascript:loadContent('#popoutBox', 'inst.html');'>click btn</a></td>";
    but the single quote around javascript have to be double
    Code:
    href="javascript:loadContent('#popoutBox', 'inst.html');"
    how can do this? or is there a workaround??

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You can do it three ways
    1. Use single quotes
    2. Escape them with \
    3. Just output it as html/javascript



    1.
    PHP Code:
    echo '<td valign="top" align="right" height="38"><a class="textBlockClick1" href="javascript:loadContent("#popoutBox", "inst.html");">click btn</a></td>'
    2.
    PHP Code:
    echo "<td valign=\"top\" align=\"right\" height=\"38\"><a class=\"textBlockClick1\" href=\"javascript:loadContent(\"#popoutBox\", \"inst.html\");\">click btn</a></td>"
    3.
    PHP Code:
    ?>
    <td valign="top" align="right" height="38"><a class="textBlockClick1" href="javascript:loadContent("#popoutBox", "inst.html");">click btn</a></td>
    <?php
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    awesome, thank you.
    btw what does escape do?

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    backslashing ( \ ) a special character (in this case, double-quotes) tells php to treat it as the literal character, and not parse it as php code.

  5. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Wasn't really sure of a good definition so here's a link. http://en.wikipedia.org/wiki/Escape_character
    Corrections to my coding/thoughts welcome.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •