After loading the page, I'd like to (re-)assign a value to a global variable. However, it doesn't change after the attempt.
The html is dynamically generated, and contains a select. Any option can be selected when it is generated, depending on the vehicle id stored in the database. I need the old (current) vehicle id to close it out when the vehicle is changed.
<select id="selVehicle">
    <option value=""> </option>
    <option selected value='1'>9999</option>
    <option value='2'>9998</option>
    <option value='3'>9997</option>
</select>
In my .js file, I have the declaration of the global variable just before the document.ready():
var oldVehicle = -1;
$(document).ready(function () {
    $(":text").on("blur", function () {
        var tmp = ($(this).val());
        ($(this).val(tmp.toUpperCase()));
    });
    //lots more onblurs and onchanges//
    setOldVehicle();
});
function setOldVehicle() {
    oldVehicle = $('selVehicle option:selected').val();
    alert(oldVehicle);
}
When I run it, the alert still says "-1". How do I update the oldVehicle variable after the page is loaded?
 
     
    