Returning an integer from a select box - JavaScript

Posted by Ross on Stack Overflow See other posts from Stack Overflow or by Ross
Published on 2010-06-17T21:15:08Z Indexed on 2010/06/17 21:23 UTC
Read the original article Hit count: 252

Filed under:
|
|

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 :(

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about newbie