Jump to content

Java Script functions


john-iom

Recommended Posts

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????

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.