Javascript - Uncaught Typeerror: Cannot Read Property 'value' Of Null
Solution 1:
Edit:
Slightly different implementation that works: http://jsfiddle.net/SfTR2/ Make sure the JS is loaded after the HTML, or use window.onload
Original answer:
You need to get the length within the validation function:
functionvalidatePhone() {
var phonenum = document.getElementById("dvr").value.length; //MOVE IT HEREif (phonenum == 10){
document.getElementById('phoneval').innerHTML="<-- Valid";
}
else{
document.getElementById('phoneval').innerHTML="<-- Not Valid";
}
}
As previously you were caching the empty length.
Also, as @su mentioned, you need to use innerHTML
Solution 2:
add
validatePhone();
to the end of the script (you defined the function but never called it). And change innerhtml to innerHTML
Post a Comment for "Javascript - Uncaught Typeerror: Cannot Read Property 'value' Of Null"