Returning an integer from a select box - JavaScript
- by Ross
Very simply, I want to be able to access the year from the select box as an integer. In my test, my alertbox is telling me the value is undefined.
<form name="form1" method="post" action="">
<label>birth year
<select name="birth year" id="dueYear">
<OPTION VALUE='' SELECTED>--Year--</OPTION>
<OPTION VALUE='2011'>2011</OPTION>
<OPTION VALUE='2010'>2010</OPTION>
<OPTION VALUE='2009'>2009</OPTION></SELECT>
</select>
</label>
</form>
<script type="text/javascript">
var dueDateYear = parseInt(document.getElementById("dueYear"));
</script>
<button onclick="alert(dueDateYear)">Click Me!</button>
All I want it to do, is tell me the year I have selected -- any help would be appreciated, I am a newbie :(