Solved

Dropdown

Posted on 2001-06-14
8
344 Views
Last Modified: 2010-04-09
I'm drawing a blank here. I can't remember how to redirect
to a site when picks an option within my dropdown...

Thanks ! :-)
0
Comment
Question by:MNY
  • 3
  • 3
  • 2
8 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6191603
setup an array of the urls you want to go to and a function
to set the loction in the head:


<script language="JavaScript">
<!--
   var theUrls new Array("url", "url" "url")
   function redirect(pntr)
   {
      window.location=theUrls[pntr]
   }
//-->
</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.selectedIndex)">
<option> first url
<option> second url
<option> third url
</select>


HTH

Cd&
0
 

Author Comment

by:MNY
ID: 6191642
What if I have 10 dropdowns in the same page?
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6191686
In that case you could simply do:

<html>
<head>
</head>
<body>
<form>
<p>
<select onChange="window.location = this.options[this.selectedIndex].value;">
<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.selectedIndex].value">
<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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
a.marsh earned 100 total points
ID: 6191690
The onChange is identical for each select box and the value of each option is the URL to redirect to.

:o)

Ant
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6191735
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[subscript]
   }
//-->
</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.selectedIndex)">
<option> first url
<option> second url
<option> third url
</select>

<select onChange="redirect(3,this.selectedIndex)">
<option> fourth url
<option> fifth url
<option> sixth url
</select>


Cd&
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6191759
Glad to help - why only a B grade?!?!?

Ant
0
 

Author Comment

by:MNY
ID: 6191783
My mistake. Sorry Ant.
I'll make it up to you...
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6191793
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&

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
document.write() deleting all existing HTML 5 68
Obtaining data on ASP 8 35
Html Newline 7 29
CSS for Popup in ASP.NET 4 11
Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question