You need to write inside the element or give the element a value, or you must use the document entry as follows:
<html> <head> <script type="text/javascript"> function myfunction() { document.getElementById("lblMessage").innerText = "hello"; document.getElementById("txtMessage").value = "hello"; </script> </head> <body> <form> <script type="text/javascript"> document.write("This is written while page processed by browser !<br />"); </script> <input type="text" id="txtMessage" /><br /> <span id="lblMessage"></span><br /> <input type="button" onclick="myfunction()" value="Call function"> </form> </body> </html>
source share