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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a search box to type custom words which link to places.

    Hi, I'm really new to Javascript. Recently in my IT class, we made a HTML page which would open a popup box, where the user could enter a key word. When the user pressed enter, the page would navigate to a specific page. The code we used was:
    Code:
    <script language = "JavaScript">
    where = window.prompt ("Please tell me where you would like to go.");
    switch (where){
    case "Digg" :
    	window.location = "http://www.digg.com" ;
    	break;
    default:
    	window.location = "http://www.google.com" ;
    }
    </script>
    What I am hopeing to do, is implement this code on my workplaces server, and have the keywords link to other html documents within the server. However when I tested this, for some reason the links are not working. Can this actually be done? Am I missing something silly? Are there any other ways of doing this?

    Thanks in advance
    Last edited by rjg117; 03-03-2010 at 04:31 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,910
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Javascript is case sensitive, so "Digg" != "digg".

    Improve it with

    Code:
    where = window.prompt ("Please tell me where you would like to go.","").toLowerCase();
    switch (where) {
    case "digg" :
    window.location = "http://www.digg.com" ;
    break;
    <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead.

    "I do not fear death. I had been dead for billions and billions of years before I was born, and have not suffered the slightest inconvenience from it". - Mark Twain, US humorist, novelist, short story author, & wit (1835 - 1910)


  •  

    Posting Permissions

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