Q: Initial Input Value in Javascript I have a page that is generated dynamically via the URL (GET Method). This dynamic page generates among a lot of other stuff the following line of HTML:
<input type='hidden' name='device' id='device' value='abcd' />

I am also loading several javascript functions, and I want one them to be able to read the initial value of 'device', however, it doesn't seem to be able to read the initial value on the intial page load. It will read it if the javascript function is fired again after the page load.
I am using the following code in my .js file
jQuery(document).ready(function(){
    var device = jQuery('#device').val();
});

When debugging, on the intial page load device is simply set to 'undefined' Anyone have any ideas? Thanks.
Brian

A: This means the element isn't available by the time you are looking for its value, you can either use onload event or put your script before </body> tag.
This should work:
$(window).load(function(){
  var device = jQuery('#device').val();
});


A: If you load those JavaScript functions together with the HTML that you receive as a response to an AJAX request - it is possible that by the moment your JS executes this code:
jQuery(document).ready(function(){
    var device = jQuery('#device').val();
});

it refers to the existing DOM? If you don't reload your body - I don't see this event firing when you insert the received HTML into your existing DOM.
