user187680
user187680

Reputation: 673

How can I use onchange to feed javascript the users selection in a dropdown list?

I know this question is simple, but I couldn't find it elsewhere so I thought it would be appropriate to ask.

I have a simple drop down list. I use onchange to trigger an event when the selection is changed. I want to know what I need to do in order to turn the selection into a variable within javascript. So that I can use that variable to do something else (specifically to populate another dropdown list using a switch statement).

Thanks

Upvotes: 0

Views: 177

Answers (1)

Peter
Peter

Reputation: 5156

Not sure if this is what you want:

var optionSelected = 0;

var select = document.getElementById('mySelect');

select.onchange = function() {
    optionSelected = this.value;
    alert(optionSelected);
}​​​​​;​

demo: http://jsfiddle.net/vTDAQ/1/

Upvotes: 2

Related Questions