Solved

Dropdown

Posted on 2001-06-14
8
337 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now