I'm trying to get the value of input select option without submitting the form (need to keep it available while displaying the live results). I then need to use this value with a global variable to be inserted in an array later on. Because I can't use submit, I need to find a way to update this value if the user changes the option (ie probably using onchange).
Here's what I have currently (doesn't work):
html
<select id="color" > <option value="">select:</option> <option value="blue">Blue</option> <option value="red">Red</option> <option value="yellow">Yellow</option> </select>
javascript
document.getElementById('color').onchange = function() { var colorInput = this.value; console.log(colorInput); }; updated
Okay, no using inline javascript, I get it. I updated the script above to reflect most of the answers I'm getting - which are not addressing my central problem. Tracking the input option value within the script is no problem; I need to the value as a global variable. For some reason I can't do it.
Here's a jsfiddle that is analogous to how I need to use it: http://jsfiddle.net/agvRn/2/
It should be able to track the select option (already can) and then must be able to use this value in a separate function - in this case inserting it into the paragraph field "show".