HTML5 Posted September 3, 2010 Share Posted September 3, 2010 Why will this not work?java script: // Javascriptfunction sayHi() { var txtName = document.getElementById("txtName"); var divOutput = document.getElementById("divOutput"); var name = txtName.value; divOutput.innerHTML = name;} HTML Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>XHTML, CSS, and Javascript!</title> <script src="xgame.js" type="text/javascript"> </script> </head><body> <form action=""> <fieldset> <label>Anything here</label> <input type="text" value="" id="textName" /> <input type="button" value="Release the monkeys!" onclick="sayHi()" /> </fieldset> </form> <div id="divOutput"> Watch this space! </div></body></html> The Firefox console says txtName is nullOn line 7 var name = txtName.value; Link to comment Share on other sites More sharing options...
jeffman Posted September 3, 2010 Share Posted September 3, 2010 Spellcheck.document.getElementById("txtName");...<input type="text" value="" id="textName" /> Link to comment Share on other sites More sharing options...
HTML5 Posted September 3, 2010 Author Share Posted September 3, 2010 OPPS! my bad....It works perfectly now THANKS! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.