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
This means the element isn’t available by the time you are looking for its value, you can either use
onloadevent or put your script before</body>tag.This should work: