...

View Full Version : prompt cancel



ubik
12-31-2005, 09:54 AM
hello, good day to all. I have a bit of a problem i have this script on a page i just wrote:



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

vwphillips
12-31-2005, 10:50 AM
<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>

ubik
12-31-2005, 11:26 AM
thank you vwphillips. I appreciate that. I have seen some scripts use something like that if statement. When you use something like:


if(!where){ return; }

does the part where it has (!where) mean "if where is equal to null" ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum