Why I can't retrieve the content of a select tag in this JavaScript\JQuery function? -


i not javascript , jquery , have following problem trying retrieve value inserted select tag defined page.

so page have select tag:

<select id="idannoriferimento" onchange="setdataricagevolazione(this.value)" style="width: 150px; text-align: center" name="">     <option value="2004">2004</option>     <option value="2005">2005</option>     <option value="2006">2006</option>     <option value="2007">2007</option>     <option value="2008">2008</option>     <option value="2009">2009</option>     <option value="2010">2010</option>     <option value="2011">2011</option>     <option value="2012">2012</option>     <option value="2013">2013</option>     <option value="2014">2014</option>     <option selected="selected" value="2015">2015</option>     <option value="2016">2016</option>     <option value="2017">2017</option>     <option value="2018">2018</option>     <option value="2019">2019</option>     <option value="2020">2020</option> </select> 

then javascript function want retrieve selected value, tryed this:

function controllodate() {     alert("into controllodate()");      var annodiriferimento = $("#idannoriferimento").innerhtml;     alert("anno di riferimento: " + annodiriferimento);      ............................................................     other stuff     ............................................................ }   

so, can see, tryed retrieve select tag having id=idannoriferimento , tag tryed retrieve inner value use of innerhtml properties alert show me message undefined.

why? missing? how can fix issue?

tnx

innerhtml, javascript property won't work on jquery objects,

use $("#idannoriferimento").val() changed value, or $("#idannoriferimento").html() get inner html.

to access these properties in javascript way, need javascript element object,

$("#idannoriferimento")[0].innerhtml 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -