Student Student - 2 months ago 11
HTML Question

Uncaught TypeError: Cannot set property 'innerHTML' of null, please help me


its giving me an error on line 51




<!DOCTYPE html>
<html>
<head>
<title>Validation</title>
</head>

<body>

<div style="width:500px;height:500px;padding-right:auto;padding-left:auto;">
<form action="#" method="get" onsubmit="return FormValidation();">



<label>Current Password</label>
<input type="text" name="pass" id="pass" maxlength="16" required><br>


<label name="notif"></label>
<input type="submit" name="submit">


</form>
<script type="text/javascript">

function FormValidation(){
var passw = "against";
var opass = document.getElementById("pass").value;


if(opass != passw) {
document.getElementById("notif").innerHTML = "Your password doesn't match.";
alert('pass now match');
return false;
}
else{
document.getElementById("notif").innerHTML = opass + " " + npass + " " + rpass;
}


}

</script>
</div>
</body>
</html>





any suggestion why is there an error ?


I just want to happen is to define the password if correct
and notify it on the label.


document.getElementById("notif").innerHTML = "Your password doesn't match.";


this form for my site forgot password. We with my group is developing
a website with a user account and its for a lending cooperative. this is for our project.

Answer

Your need to change this line:

<label name="notif"></label>

to this:

<label id="notif"></label>

If the name attribute must be retained, you can try jQuery:

$("label[name='notif']").html('Your message');