MNY
asked on
Dropdown
I'm drawing a blank here. I can't remember how to redirect
to a site when picks an option within my dropdown...
Thanks ! :-)
to a site when picks an option within my dropdown...
Thanks ! :-)
ASKER
What if I have 10 dropdowns in the same page?
In that case you could simply do:
<html>
<head>
</head>
<body>
<form>
<p>
<select onChange="window.location = this.options[this.selected Index].val ue;">
<option value="" selected>-- Choose One --</option>
<option value="http://www.yahoo.com/">Yahoo</option>
<option value="http://www.google.com/">Google</option>
</select>
</p>
<p>
<select onChange="window.location = this.options[this.selected Index].val ue">
<option value="" selected>-- Choose One --</option>
<option value="http://www.yahoo.co.uk/">Yahoo UK</option>
<option value="http://www.google.co.uk/">Google UK</option>
</select>
</p>
</form>
</body>
</html>
:o)
Ant
<html>
<head>
</head>
<body>
<form>
<p>
<select onChange="window.location = this.options[this.selected
<option value="" selected>-- Choose One --</option>
<option value="http://www.yahoo.com/">Yahoo</option>
<option value="http://www.google.com/">Google</option>
</select>
</p>
<p>
<select onChange="window.location = this.options[this.selected
<option value="" selected>-- Choose One --</option>
<option value="http://www.yahoo.co.uk/">Yahoo UK</option>
<option value="http://www.google.co.uk/">Google UK</option>
</select>
</p>
</form>
</body>
</html>
:o)
Ant
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
then you end up with a bigger array and add an argument to the
function to apply an offset to the starting point in the array
for that select:
<script language="JavaScript">
<!--
var theUrls new Array("url", "url", "url","url","url","url")
function redirect(offset,pntr)
{
subscript=offset+pntr;
window.location=theUrls[su bscript]
}
//-->
</script>
the value of the first argument will be the total of all the preceeding
options. That will point to the correct starting point in the array and
the index will get applied from that starting point
<select onChange="redirect(0,this. selectedIn dex)">
<option> first url
<option> second url
<option> third url
</select>
<select onChange="redirect(3,this. selectedIn dex)">
<option> fourth url
<option> fifth url
<option> sixth url
</select>
Cd&
function to apply an offset to the starting point in the array
for that select:
<script language="JavaScript">
<!--
var theUrls new Array("url", "url", "url","url","url","url")
function redirect(offset,pntr)
{
subscript=offset+pntr;
window.location=theUrls[su
}
//-->
</script>
the value of the first argument will be the total of all the preceeding
options. That will point to the correct starting point in the array and
the index will get applied from that starting point
<select onChange="redirect(0,this.
<option> first url
<option> second url
<option> third url
</select>
<select onChange="redirect(3,this.
<option> fourth url
<option> fifth url
<option> sixth url
</select>
Cd&
Glad to help - why only a B grade?!?!?
Ant
Ant
ASKER
My mistake. Sorry Ant.
I'll make it up to you...
I'll make it up to you...
LOL. I don't what I was even thinking. The way Ant has it the right way. I've got on my HDD from the last time I answer this. Don't know where I was going with that. Sorry...bad morning.
Cd&
Cd&
to set the loction in the head:
<script language="JavaScript">
<!--
var theUrls new Array("url", "url" "url")
function redirect(pntr)
{
window.location=theUrls[pn
}
//-->
</script>
then use the onChange event of the select to fire the fucntion
the select index will be the pointer into the array, so the
opion values need to be in the same order as the array entries
<select onChange="redirect(this.se
<option> first url
<option> second url
<option> third url
</select>
HTH
Cd&