PDA

View Full Version : problem ...innerHTML and <form> tag


jef_abraham
06-29-2006, 04:09 AM
<html>
<head>
<script langu…..>
function validate()
{
document.getElementById(“h1”).innerHTML=”This is H1”;
}
</script>
</head>

<body>
<h1 id=”h1”>
<form>
<input type=”button” onClick=”validate()”>
</form>
</body>
</html>

The above code has a problem…
If we run this code then "This is H1" is displayed and disappears later…if we remove the form tag it works fine and in h1 “This is H1” is displayed…..or else if w put the button element out of the form tag even that works fine
...Can any one tell me the reason for this .....

_Aerospace_Eng_
06-29-2006, 04:18 AM
Well your h1 tag doesn't even have a closing tag. Also what editor are you using? The quotes you are using don't seem correct. Try this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function validate()
{
document.getElementById("h1").firstChild.data = "This is H1";
}
</script>
</head>
<body>
<h1 id="h1">&nbsp;</h1>
<form action="#" method="post">
<input type="button" onClick="validate()" value="Run Validate()">
</form>
</body>
</html>