...

View Full Version : How do I redirect the page with selection box thing?



cyphix
11-13-2004, 03:03 PM
Hello..

How do I go about making one of those selection boxes where when the user selects a different value it redirects the page to another URL, also can you make it stay on the page also depending on what they select?

Thanks!

codegoboom
11-13-2004, 09:54 PM
Here's one way:
<body>
<script type="text/javascript">
function redirect(val)
{
if(val == "void")
return false;
var loc = String(location);
val.substr(0, 1) == "#"
? location = loc.substring(0, loc.lastIndexOf("#")) + val
: location = val;
}
</script>
<select onchange="redirect(options[selectedIndex].value)">
<option selected value="void">[none]</option>
<option value="#heading1">H1</option>
<option value="#heading2">H2</option>
<option value="http://google.com/">Google</option>
</select>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<h1 id="heading1">Heading #1</h1>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<h2 id="heading2">Heading #2</h2>
</body>

cyphix
11-14-2004, 07:41 AM
Thanks... I'll give it a try! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum