Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: prompt cancel

  1. #1
    Regular Coder ubik's Avatar
    Join Date
    Oct 2005
    Location
    westCoast, usa
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post prompt cancel

    hello, good day to all. I have a bit of a problem i have this script on a page i just wrote:

    Code:
    <html>
    <head>
    <title>Where To</title>
    </head>
    
    <body bgcolor="#000000">
    
    <script>
    where = prompt("where to?");
    switch (where) {
    
    case "mail" :
    window.location="http://mail.yahoo.com/?.intl=us";
    break;
    
    case "coding" :
    window.location="http://www.codingforums.com";
    break;
    
    default :
    window.location="http://www.google.com/search?hl=en&q=" + where + "&btnG=Google+Search";
    }
    
    </script>
    
    </body>
    </html>
    the problem is that when someone clicks cancel it goes to the default location defined, in this case my default location is the variable + a google search, so everytime someone clicks cancel for one reason or another. the page does a google search for "null" can anyone help me? I want to know if you can define an action for when the cancel button is clicked? or any other alternative is appreciated. thanks for your time.
    "True knowledge exists in knowing that you know nothing."
    -Socrates

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,517
    Thanks
    3
    Thanked 506 Times in 493 Posts
    Code:
    <html>
    <head>
    <title>Where To</title>
    </head>
    
    <body bgcolor="#000000" onload="LinkTo();" >
    
    <script type="text/javascript">
    <!--
    
    function LinkTo(){
     var where = prompt("where to?",'');
     if(!where){ return; }
     switch (where) {
      case "mail" : {
       window.top.location="http://mail.yahoo.com/?.intl=us";
       break;
      }
      case "coding" : {
       window.top.location="http://www.codingforums.com";
       break;
      }
      default : {
       window.top.location="http://www.google.com/search?hl=en&q=" + where + "&btnG=Google+Search";
      }
     }
    }
    
    
    //-->
    </script>
    </body>
    </html>

  • #3
    Regular Coder ubik's Avatar
    Join Date
    Oct 2005
    Location
    westCoast, usa
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you vwphillips. I appreciate that. I have seen some scripts use something like that if statement. When you use something like:
    Code:
     if(!where){ return; }
    does the part where it has (!where) mean "if where is equal to null" ?
    "True knowledge exists in knowing that you know nothing."
    -Socrates


  •  

    Posting Permissions

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