I had the following:
<script type="text/javascript">
var noteid = $('#noteid').val();
</script>
<input type="hidden" name="noteid" id="noteid" value="321">
This works great… but now I’m trying to move the JavaScript off the page into a linked JS file like so:
<script type="text/javascript" src="/js/note_beta.js"> </script>
<input type="hidden" name="noteid" id="noteid" value="321">
This ext JS file has the code: “var noteid = $(‘#noteid’).val();” but it isn’t working… Is there a trick to getting this to work when it isn’t on the page itself?
Thanks
Try wrapping your jQuery code in a (document).ready function, this ensures it doesn’t run until the page has loaded and you don’t run the risk of trying to reference elements before they are added to the DOM
So change:
To this: