What type of form input should the user expect to give null in javascript?

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 the blank line "" indicates that nothing was entered, but what type of input would the user have to enter that would mean null

?

+3


source to share


1 answer


The value

element attribute input

returns a string that will contain the text entered by the user, otherwise it will be empty ( ""

). In this case, there is not and should not be a reason to check null

, because a string (empty or not) can never be equal null

.



+3


source







All Articles