• Javascript – array, if, condition

    RenaldoL25 Member

    Please tell me how it possible to finish this form validation in way which i start. I will give a part of code.

    
    
    
    
         
    Name of student:

    etc.

    When i fill up all column it still writes me:"You must fill up all column". Where i make mistake when it wont to finish checking column rows?

    Next what i want to do is for every column if it not entered to alert me. I suppose i have to do something as this:

    alert(x[0] + "You must fill up name);
    alert(x[1] + "You must fill up surname); 
  • Abhey Member
    var form = document.forms[0];
    for(var i = 0; i < form.length; i++){
        if(form[i].value === undefined || typeof(form[i].value) === 'undefined' || form[i].value == "" || form[i].value.length < 1)
        {
            alert('You didn't fill in all the columns');
            return false; //Showing the message one time should be enough
        }
    }
    

    This is the simplest snippet I could think of for your case.
    You are checking for 'null'. Javascript doesn't have a 'null-object'. Check for undefined, or typeof(object). See my example for this. Personally I'd rather use the last bit of the if in my example, because if someone fills in his or her name as a single letter, it's easier to check for that as well.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
en_USEnglish