Click to See Complete Forum and Search --> : redirect function
Hi,
I need a function/script that sends users to page1.htm if they select option1 from a drop down, and send them to page2.htm if they select option2 from the same drop down.
Here's what I have:
function Redirect ()
{
if (document.FrontPage_Form1.menu1.option.value == "Red")
window.location.href = "Red.htm";
else
window.location.href = "Blue.htm";
}
// End -->
Then on the submit button I use an onclick event to call the function.
It only works if none of the other fields on the form are completed. If other fields are completed it always goes to Red.htm.
Help please!!
fredmv
01-09-2004, 01:01 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
</head>
<body>
<form action="#">
<div>
<select onchange="if(selectedIndex != 0) location = options[selectedIndex].value;">
<option value="">< select an option ></option>
<option value="page1.htm">Option 1</option>
<option value="page2.htm">Option 2</option>
</select>
</div>
</form>
</body>
</html>
I'm not sure what to do with this code . . . can you please explain alitte more? Sorry - i'm a novice :-)
ok - actually I got that working.
however, the page shouldn't jump until after the form's sumbit button is clicked.
what is the best way to that?
fredmv
01-09-2004, 01:28 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
<script type="text/javascript">
//<![CDATA[
function go(e) { if(e.selectedIndex != 0) location = e.options[e.selectedIndex].value; return false; }
//]]>
</script>
</head>
<body>
<form action="#" onsubmit="return go(elements[0]);">
<div>
<select onchange="">
<option value="">< select an option ></option>
<option value="page1.htm">Option 1</option>
<option value="page2.htm">Option 2</option>
</select>
<input type="submit" value="Submit" />
</div>
</form>
</body>
</html>
Hi,
I've put the new code into my form and the same problem exists where it always goes to the one page rather than what is selected.
any other thoughts?
fredmv
01-09-2004, 04:00 PM
I test all the code I provide. It worked fine when I tested it locally, and thus the error must be on your part.
Hi Fred,
The code works fine outside of the form that I'm using it in, and it still works when none of the fields on my form are filled in.
The problem only seems to happen when all the form fields are completed. And in that case, it sends the user to page1.htm no matter if the page2.htm value field is selected.
I'm using Frontpage 2002 as my base and then adding javascript to it - not sure if that makes a difference?
I'm not sure where to look or how to debug this problem and would really appreciate any additional thoughts or help.
Thanks,
Liz