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
https://forums.phpfreaks.com/topic/49421-java-script-functions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.