Since your script is running before there is a label on the page (in the DOM). Either put the script after the label, or wait until the document is fully loaded (use the OnLoad function, such as jQuery ready() or http://www.webreference.com/programming/javascript/onloads/ )
This will not work:
<script> document.getElementById('lbltipAddedComment').innerHTML = 'your tip has been submitted!'; </script> <label id="lbltipAddedComment">test</label>
This will work:
<label id="lbltipAddedComment">test</label> <script> document.getElementById('lbltipAddedComment').innerHTML = 'your tip has been submitted!'; </script>
This example (jsfiddle link) maintains order (script first, then label) and uses onLoad:
<label id="lbltipAddedComment">test</label> <script> function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } addLoadEvent(function() { document.getElementById('lbltipAddedComment').innerHTML = 'your tip has been submitted!'; }); </script>
Konerak Dec 20 '10 at 10:28 2010-12-20 10:28
source share