Jump to content

Open New Window With A Select Form


bukwus
 Share

Recommended Posts

HiI'm building a drop down menu and each option link needs to open a new window. Here's the code:

<form><select onChange="if(options[selectedIndex].value) window.location.href=(options[selectedIndex].value)"><option>Select a Country</option><option value="http://www.link.com">Global</option>etc.

I'm thinking there's extra code I need to add to the onChange, but I'm not sure what that would be. Can anyone help me with this?Thanks

Link to comment
Share on other sites

You have the right idea. So far, the script is looking for variables named options and selectedIndex. These variables do not exist. They are properties of the select object. So you need a reference to the select object to access those properties. The good news is that your script is embedded in the select object itself. So you can get the reference you need just by using the this keyword. The following should work:if(this.options[this.selectedIndex].value)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...