Jump to content

Form won't validate


NathanLedet

Recommended Posts

Javascript:

function validate() {
if(document.form2.client.value==''){
	alert('Fill in the Username before submitting');
	return false;
	}else{
	return true;
		}

if(document.form2.project.value==''){
	alert('Fill in the Password before submitting');
	return false;
	}else{
	return true;
		}
}

 

and the HTML form:

 

<form ACTION="client_login_process.php" id="form2" name="form2" method="POST" onSubmit='return validate();'>

  <label></label>

  <table width="241" border="0" align="center">

    <tr>

      <td colspan="2"><h2 class="style4">Project  Login</h2></td>

    </tr>

    <tr>

      <td width="79"><span class="style3"><strong>

       

      </strong>       

       

      </span>        <span class="style2">

   

      </span>      <div align="right" class="style3"><strong>Client:</strong></div>      </td>

      <td width="152"><input name="client" type="text" id="client" tabindex="5" maxlength="20" /></td>

    </tr>

    <tr>

      <td><span class="style3"><strong>

     

      </strong>       

       

      </span>        <span class="style2">

     

      </span>    <div align="right" class="style3"><strong>Project:</strong></div>      </td>

      <td><input name="project" type="text" id="project" tabindex="6" maxlength="20" /></td>

    </tr>

 

    <tr>

      <td> </td>

      <td><input name="submit1" type="submit" id="submit1" tabindex="8" value="Login" /></td>

    </tr>

 

  </table>

 

</form>

 

 

When I test this, only the 'client' will show the error message, but the 'project' never validates.

Link to comment
https://forums.phpfreaks.com/topic/115840-form-wont-validate/
Share on other sites

Because upon the first validation you are returning true. Don't "return" until you want to exit the function.

 

function validate()
{
    if(!document.form2.client.value)
    {
        alert('Fill in the Username before submitting');
        return false;
    }

    if(!document.form2.project.value)
    {
        alert('Fill in the Password before submitting');
        return false;
    }

    return true;
}

Link to comment
https://forums.phpfreaks.com/topic/115840-form-wont-validate/#findComment-595629
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.