SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onclick-> return confirm('..') doesn't work. why?

    Hello,
    I used to use below code to make it confirm.

    PHP Code:
    echo "<td<a href=\"makeAvailable.php?id=$id\" onclick=\"return confirm('Are you sure you want to share{$title}?');\">Share this item</a></td>"
    It worked fine until $title was "What's so amazing?"
    As you see, $title has ' in that, so no confirm box is shown, just go to the makeAvailable.php right away.
    Is there anyway I can solve this problem?

    Thanks

  2. #2
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm.. try this.. i typically use single quotes for html so i dont have to escape all attribute values..
    PHP Code:
    echo '<td><a href="makeAvailable.php?id='.$id.'" onclick="return confirm(\'Are you sure you want to share '.$title.'?\')">Share this item</a></td>'

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No it doesn't work

  4. #4
    SitePoint Member
    Join Date
    May 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try

    PHP Code:
    echo '<td><a href="makeAvailable.php?id='.$id.'" onclick="return confirm(\'Are you sure you want to share 'addslashes($title) .'?\')">Share this item</a></td>'

  5. #5
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Join the dark side, use print with double quotes....
    PHP Code:
    print ("<td><a href=\"makeAvailable.php?id=$id\" onclick='return confirm(\"Are you sure you want to share $title?\",alert(\"eek a mouse!\"))'>Squash this item</a></td>"); 
    Last edited by paulyG; Nov 8, 2005 at 16:31. Reason: forgot beautificationalising the code

  6. #6
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alright well i have no idea what your problem is then.. i tried this and it works fine..
    PHP Code:

    <html>
    <body>

    <?php
    $id
    =1;
    $title "What's happening";
    echo 
    '<a href="makeAvailable.php?id='.$id.'" onclick="return confirm(\'Are you sure you want to share 'addslashes($title) .'?\')">Share this item</a>'
    ?>
    </body>
    </html>
    that works fine.. all i changed was i took out your <td></td> tags. also note in your original post you were missing a closing > on the first td..

    Edit:


    and i added addslashes.


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
  •