0

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

1
  • You want to get the <select> value? Commented Aug 11, 2012 at 0:20

1 Answer 1

2

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.