Jump to content

Trouble with innerHTML functions


HTML5

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...