Jump to content
  • Advertisement
Sign in to follow this  
BeanDog

[web] javascript onclick on 'select' element (combobox)

This topic is 4430 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to make a combobox that, when a new item is selected in it, navigates the browser to a new page based on the entry in the combobox. I've googled for "html select onclick", "html select javascript onclick navigate", etc., but haven't been able to find anything. Currently it looks something like this:
<script>
function Chart(qs)
{
	window.location.href = 'http://www.nda.com/traffic_chart.php' + qs;
}		
</script>
<select>
	<option></option>
	<option onclick="Chart('?Month=5&Year=2006');">May 2006</option>
	<option onclick="Chart('?Month=6&Year=2006');">June 2006</option>
	<option onclick="Chart('?Month=7&Year=2006');">July 2006</option>
</select>

This doesn't work very well. If I click on the box, it runs the script before I select a new item in the box. How do I do this?

Share this post


Link to post
Share on other sites
Advertisement

<select onchange="if (this.selectedIndex > 0) document.location.href='http://www.nda.com/traffic_chart.php?' + this.value;">
<option></option>
<option value="Month=5&Year=2006">May 2006</option>
<option value="Month=6&Year=2006">June 2006</option>
<option value="Month=7&Year=2006">July 2006</option>
</select>



Obviously, feel free to use a function if you want to avoid the inline JS.

Share this post


Link to post
Share on other sites

This topic is 4430 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!