Solved

Dropdown

Posted on 2001-06-14
8
338 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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 …

863 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

24 Experts available now in Live!

Get 1:1 Help Now