View Full Version : Creating a search box to type custom words which link to places.

03-03-2010, 05:23 AM
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:

<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" ;
window.location = "http://www.google.com" ;

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

Philip M
03-03-2010, 08:46 AM
Javascript is case sensitive, so "Digg" != "digg".

Improve it with

where = window.prompt ("Please tell me where you would like to go.","").toLowerCase();
switch (where) {
case "digg" :
window.location = "http://www.digg.com" ;

<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)