javascript - Assign value to global variable -


after loading page, i'd (re-)assign value global variable. however, doesn't change after attempt.

the html dynamically generated, , contains select. option can selected when generated, depending on vehicle id stored in database. need old (current) vehicle id close out when vehicle changed.

<select id="selvehicle">     <option value="">&nbsp;</option>     <option selected value='1'>9999</option>     <option value='2'>9998</option>     <option value='3'>9997</option> </select> 

in .js file, have declaration of global variable before document.ready():

var oldvehicle = -1; $(document).ready(function () {     $(":text").on("blur", function () {         var tmp = ($(this).val());         ($(this).val(tmp.touppercase()));     });      //lots more onblurs , onchanges//      setoldvehicle(); });  function setoldvehicle() {     oldvehicle = $('selvehicle option:selected').val();     alert(oldvehicle); } 

when run it, alert still says "-1". how update oldvehicle variable after page loaded?

issue here oldvehicle = $('selvehicle option:selected').val();

since using id need pass # id selector

oldvehicle = $('#selvehicle option:selected').val(); 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -