...

View Full Version : window.location() problem



asherinho
08-27-2008, 02:34 PM
Hi! can anyone help me here,whats wrong with the codes below.I want to direct user to another page tryn2.html or tryn3.html depending on the selection user made in the select field.The window.location() function doesn't work the way it should be


html>
<head><title>clr</title>
<script type="text/javascript">
function validate_form ( ){
if ( document.myform.nam.selectedIndex == 1 )
{
var valid=confirm ( "Are u sure?" );
if(valid==true){

window.location=("tryn2.html");

}else{
window.location=('tryn3.html');
}
}
}
</script>
</head>
<body>

<form name="myform" onSubmit="return validate_form ( );">
<select name="nam">
<option>Select one..</option>
<option>Delete</option>
<option>George</option>
</select>
<input type="submit" value="submit">
</form>
</body>
<html>

JUD
08-27-2008, 03:04 PM
There's no need for the parentheses after window.location.

Use

window.location = 'tryn2.html'

instead of

window.location = ('tryn2.html')

mugalata
08-27-2008, 03:10 PM
try this





<html>
<head><title>clr</title>
<script type="text/javascript">
function validate_form(){
if ( document.myform.nam.selectedIndex == 1 )
{
var valid=confirm ( "Are u sure?" );
if(valid==true){

window.location = "tryn2.html" ;

}else{
window.location = "tryn3.html" ;
}
}
}
</script>
</head>
<body>

<form name="myform" onSubmit="validate_form(); return false;">
<select name="nam">
<option>Select one..</option>
<option>Delete</option>
<option>George</option>
</select>
<input type="submit" value="submit">
</form>
</body>
<html>

stevenx
08-27-2008, 04:19 PM
and in your if statement

if(valid){

}
else{

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum