i'm trying to display a validation error message without using an alert box. But its not working. Previously I've used "innerHTML" successfully. But i don't understand why it doesn't work here. This is my code.
function validate()
{
if(document.regform.fname.value.length=="")
{
document.getElementById("error").innerHTML="error";
}
}
<header>
<h1>SIGN UP</h1>
</header>
<div class="div1"><img src="img.jpg" width="250px"></div>
<div class="div2" id="div2">
<form name="regform" onsubmit="return validate()">
<label><input type="text" name="fName" id="fna"></label>
<input type="submit" name="submit" value="Sign Up" >
<p id="error"></p>
</form>
</div>
<footer></footer>