Jump to content

html in the "innerHTML = "


djp1988

Recommended Posts

How can I include html such as input types into the javascript in the innerHTML part?I wish to include a <input type="text" name="Name" size="30">element in here but from initial tests by using the following code, the script doesn't work:

<!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"><head>	<title>Test</title><style type="text/css">#table1 {	background-color:green;	letter-spacing:1px;	}</style><script type="text/javascript">function makeNew() {	document.getElementById("form").innerHTML =	"Name:<INPUT TYPE="text" name="Nom" SIZE="30"><br />Email:<br />Locality:<br />Information:<br />";	document.getElementById("already").childNodes[0].nodeValue = 	"Complete the following form to submit your obseration:";	}</script></head><body><table width="400" border="1" cellspacing="0" cellpadding="5" id="table1">  <tr>	<td><button onclick="makeNew()">Submit an obs.</button><p id="already">Click above to submit an observation</p><p id="form"></p></td>  </tr></table></body></html>

Link to comment
Share on other sites

You have to escape the quotes or use single quotes for the main quote.

document.getElementById("form").innerHTML = "Name:<INPUT TYPE=\"text\" name=\"Nom\" SIZE=\"30\"><br />Email:<br />Locality:<br />Information:<br />";

Or

document.getElementById("form").innerHTML = 'Name:<INPUT TYPE="text" name="Nom" SIZE="30"><br />Email:<br />Locality:<br />Information:<br />';

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...