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