Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: alert box with ok and cancel buttons, when you click ok you get taken to...

  1. #1
    Join Date
    Jun 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default alert box with ok and cancel buttons, when you click ok you get taken to...

    Hi all,
    I need help making an alert box like this:

    that pops up when you click a link,and when you click the "ok" button it takes you to the links destination and when you click cancel nothing happens.

    Does anyone know how to do this?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, it depends upon what you want to have happen if javascript is disabled. In this version, with javascript disabled, it will act as a normal link:

    Code:
    <a href="http://www.google.com/" onclick="return confirm('Do You Really Want to go to Google?');">Google</a>
    With javascript enabled, it will behave just as you asked it to. If the game cannot be used and played without javascript, this is probably the best method. However, if javascript would be required at the destination but not on the originating page or confirmation is required for legal or other reasons, you could do this:

    Code:
    <a href="javascript:void(0);" onclick="theVar=confirm('Do You Really Want to go to Google?');setTimeout('if(theVar){window.location=\'http://www.google.com/\'}', 0);">Google</a><br>
    <noscript>Javascript Enabled required for above link</noscript>
    Last edited by jscheuer1; 07-21-2006 at 04:15 AM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    How to change this so that, when you click OK, it initiates an action? (click on delete icon, press OK and it calls the javascript to delete the row) i have the script to delete a row.. how should i call a js function within this confirm syntax?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Generally, you can just put it in the flow of the delete function. Something like:

    Code:
    function delete(){
    do some prep stuff here if you like
    var answer=confirm('Do you Really want to do this?')
    if (answer) {
    do the thing here
    }
    do some clean up stuff here if needed
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks jscheuer1

  6. #6
    Join Date
    Jun 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks jscheuer1, that would work except I'm using dynamic drives Fold-out external menu and it dissapears whenever I have an onclick attribute on this link. Here ill post some code so you can see what I'm dealing with here, its php.

    PHP Code:
        <td valign="top"><div align="center">
    <?php 
    for ($i=0$i <= count($arraymember)-1$i++){

        echo(
    "<a href=\"?world=" $arraymember[$i] . "&detail=" $detailq "\" class=\"world\" target=game >World " $arraymember[$i] . "</a></ br>");

    }
    ?>
    </div></td>
    I also tried adding code for the onclick event like this:
    PHP Code:
    $onclick "onclick="return confirm('Do You Really Want to go to Google?');"" 
    And then using . $onclick . to call it but it didnt like it and it hid the foldout menu.

    Anymore ideas?

    Heres where its being used:
    http://runecore.selfip.com:82/switch/switchindex.php
    and heres the link to the menu file:
    http://runecore.selfip.com:82/switch/menu.php

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?php 
    for ($i=0; $i <= count($arraymember)-1; $i++){
    
        echo("<a href=\"?world=" . $arraymember[$i] . "&detail=" . $detailq . "\" class=\"world\" target=game >World " . $arraymember[$i] . "</a></ br>");
    
    }
    ?>
    can be summed up as:
    Code:
    <?php 
    for ($i=0; $i < count($arraymember); $i++)
      echo(
        '<a ' .
          'href="?world=' . $arraymember[$i] . '&amp;detail=' . $detailq . '" ' .
          'class="world" ' .
          'target="game" ' .
          'onclick="return window.confirm(\'Do You Really Want to go to Google?\');"' .
        '>' .
          'World ' . $arraymember[$i] .
        '</a>' .
        '<br>'
      );
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jun 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It works this way! Thank you Twey, what was differnet that made it work?

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Most important one was the proper escaping of the quotes I tidied up the HTML somewhat too, though.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Jun 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    you mean by using single quotes ' instead of double quotes " ?

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
  •