Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you make a jump drop down menu?

Status
Not open for further replies.

benluke4

Technical User
Jan 27, 2005
127
GB
Hi ive never done this before but would like to know how you do it.

I have this so far:
Code:
<form>
<table width="150" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
      <td> 
        <select name="location" class="FormField">
          <option value="00">Select a country </option>
          <option value="Afghanistan">Afghanistan</option>
          <option value="Albania">Albania</option>
          <option value="Algeria">Algeria </option>
          <option value="American Samoa">American</option>
          <option value="Andorra">Andorra</option>
          <option value="Angola">Angola </option>
        </select>
      </td>
</tr>
</table>
</form>

How do you make it so when the user selects from the dropdown menu it takes them to the correspoding page automatically.

Im guessing you have to use javascript?

Thanks

Ben
 
Im guessing you have to use javascript?
You are correct on that, but here's a quick and dirty example:
Code:
<select onchange='window.location=this.value'>
<option value='[URL unfurl="true"]http://www.google.com'>Google</option>[/URL]
<option value='[URL unfurl="true"]http://www.tek-tips.com'>Tek-Tips</option>[/URL]
</select>

-kaht

Do the chickens have large talons?
 

Something like this should work:

Code:
<select name="location" class="FormField" onchange="if (this.value != '00') document.location = 'newPage.asp?selValue=' + this.value;">

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]

 

Ah yes... "document.location" should indeed be "window.location". Not sure what I was thinking ;o)

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]

 
Thanks guys,

Is there a way of doing so it still works if Java is turned off?

Thanks

Ben
 
If you want it to trigger the instant that the dropdown is changed then the answer is no. However, you could create some situation where you select the appropriate page and then submit, and the server would direct you accordingly, but I don't think this is what you were originally asking.

-kaht

Do the chickens have large talons?
 
Im using Billy Rays example but keep getting page can not be found?

Here's my code

Code:
<select name="location" class="FormField" onchange="if (this.value != '00') window.location = 'newPage.asp?selValue=' + this.value;">
          <option value="00">More NVQ's.....</option>
          <option value="registered_managers.php">Registered Managers Award</option>
          <option value="Albania">Reg Managers/Care 4 combined</option>
          <option value="Algeria">Health & Social NVQ Care Level 4</option>
          <option value="American Samoa">Health & Social NVQ Care Level 3</option>
          <option value="Andorra">Health & Social NVQ Care Level 2</option>
          <option value="Angola">A1 Assessor</option>
		  <option value="Angola">V1 Internal Verifier</option>
        </select>

here's whats coming up in the addres bar on the not found page

Ive checked and registered_managers.php is defo on the server

any thoughts??

Thanks

Ben
 
That's what you get for listening to BRPS, I think he's only like 12 years old or something. Since you are defining the name of the asp file to be opened in the value of the <option>, you don't need to use newPage.asp?selValue. Change the code to this:
Code:
<select name="location" class="FormField" onchange="if (this.value != '00') window.location = this.value">

Please note that you will have to change the value of each of your <option> tags to reflect the PHP page that is to be opened for each <option>

-kaht

Do the chickens have large talons?
 
Cheers Kaht, i must remember to listen to you next time! ;)

thummdasss??? [thumbsup2]
 
Wouldn't it be this?
Code:
<select name="location" class="FormField" onchange="if ([red]this[this.selectedIndex].value[/red] != '00') window.location = this.value">

Adam

Pedro offers you his protection
 
this.value will still work, but to be completely thorough adam is right, although with a little modification:
Code:
this[COLOR=red].options[/color][this.selectedIndex].value

-kaht

Do the chickens have large talons?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top