john-iom Posted May 1, 2007 Share Posted May 1, 2007 Hey is it possbile to have 2 java script functions that check for an empty feild and then check for the login in pw? function Form(fldLogin, fldPassword) { // check for empty field if (fldLogin.value == "") { alert("You Must Enter Your User Name"); fldLogin.focus(); return false; } // check for empty field else if (fldPassword.value == "") { alert("You Must Enter Your Password"); fldPassword.focus(); return false; } else { return true; // validation ok } } function checkPass(name_str, password_str) { var i; // could use 2-dimensional array but keep it simple ... var nameList = new Array("fred", "alice", "ian", "john"); var passList = new Array("dog", "cat", "fish", "bird"); for (i in nameList) { if (name_str == nameList[i]) { alert("Name found!"); // test if (password_str == passList[i]) { alert("Correct password match."); // test return true; } else { alert("Password NOT matched."); // test return false; } } } alert("Name NOT found."); // test return false; } <form action="" id="loginForm" method="get" name"customer_login" onsubmit="return Form(this.name_fld, this.password_fld);" onsubmit="return checkPass(this.name_fld.value, this.password_fld.value);"> <fieldset> <legend>Log in</legend> <div class="row"> <label for="name_fld">User name: </label> <input class="field" name="name_fld" type="text" id="name_fld" size="25" /> </div> <div class="row"> <label for="password_fld">Password: </label> <input class="field" name="password_fld" type="text" id="password_fld" size="25" /> </div> <div align="center"> <input name="cmdLogin" type="submit" id="cmdLogin" value="Login"/> </div> <div align="center" class="forgotpassword">Forgotten password </div> </fieldset> </form> So what i'm trying todo is first of all see if user login is = "" or password is = "" then send an error to get user to type something after they have to get the other java script function to find a name and the pw to login. I tried to put the two functions togethere but that wont work. I've also tried putting 2 sumbit button in the action form but that wont work is there a solution to this???? Quote Link to comment Share on other sites More sharing options...
xenophobia Posted May 1, 2007 Share Posted May 1, 2007 onsubmit="return Form(this.name_fld, this.password_fld); return checkPass(this.name_fld.value, this.password_fld.value);" use ';' to separate functions. But this involved return... Might not working. But give a try. Hope it helps you Quote Link to comment Share on other sites More sharing options...
fenway Posted May 1, 2007 Share Posted May 1, 2007 You can't return twice -- nor can you have two onsubmit handlers -- have one consolidated function that calls the other. Quote Link to comment Share on other sites More sharing options...
john-iom Posted May 1, 2007 Author Share Posted May 1, 2007 How do I call one to the other??, also could someone tell me how to code it to check for a vaild email address? I looked on the websites and could not get it to work Quote Link to comment Share on other sites More sharing options...
fenway Posted May 1, 2007 Share Posted May 1, 2007 Have the last line of one of the functions call the other, get it's return value (which I assume is a boolean), and then return the logical AND of both. As for the e-mail regex, I just saw a thread earlier this week, so try searching for it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.