Reputation: 377
I'm not sure if my question is clear enough, but consider the following function:
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x == null || x == "") {
alert("First name must be filled out");
return false;
}
}
What I don't get is "null"; I understand that an empty string "" indicates nothing has been inputted, but what would be the type of input by a user that would imply null
?
Upvotes: 3
Views: 81
Reputation: 96810
The value
attribute of an input
element returns a string, which will contain the text inputted by the user, or otherwise it will be empty (""
). There is not and should not be a reason to check for null
in the condition because a string (empty or not) can never be equal to null
.
Upvotes: 3