Alegro
Alegro

Reputation: 7966

javascript form validation doesn't work properly

I'm trying to validate joinUs form

<form id="frmReg" method="post" onsubmit="return valRegs()" action="memb_area/register.php">  
//js:
function valRegs(user, pass) {
    if (!user || !pass) {
        document.getElementById('labInfo').innerHTML = "* White fields required !";
        return false;
    }
    var x = document.forms["frmReg"]["mail"].value;
    var atpos = x.indexOf("@");
    var dotpos = x.lastIndexOf(".");
    if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
        document.getElementById('labInfo').innerHTML = "Incorrect mail !";
        return false;
    }
};

Whichever field is filled or not, whatever is the content of mail field - the result is always: "* White fields required !". What's wrong, please?

Upvotes: 1

Views: 440

Answers (3)

Sibu
Sibu

Reputation: 4617

how are you passing the parameters to the js function. try

function valRegs() {
        var user = document.getElementById('user').value;
         var pass = document.getElementById('pass').value;
    if (!user || !pass) {
        document.getElementById('labInfo').innerHTML = "* White fields required !";
        return false;
    }

};

Upvotes: 1

Alexander Larikov
Alexander Larikov

Reputation: 2339

onsubmit="return valRegs()" missed parameters

Upvotes: 2

jhauberg
jhauberg

Reputation: 1430

The function will never be supplied the user and pass parameters. You will have to find these elements manually in the javascript.

Upvotes: 3

Related Questions