I am trying to simply check if I have an empty input text box but I get this error when I run this in Chrome:
Uncaught TypeError: Cannot read property 'length' of undefined.
Here is how I go about doing it. I check for DOM readiness and then call the function:
function walkmydog() {
//when the user starts entering
if(document.getElementById('WallSearch').value.length == 0) {
alert("nothing");
}
}
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", walkmydog, false);
}
WallSearchis the ID of theinputelement? If it was, you would not get that error: jsfiddle.net/fkling/x9Vf2 - Felix KlinggetElementById('WallSearch'), it does not have avalueproperty. Every form field has avalueproperty, hence it seems it does not return the right element. Please post your HTML or create a jsfiddle.net demo. - Felix Kling