开发者

separate validation of two forms with jquery

I have two forms in one page and i would like to validate each form separately DEPENDING on what the user fills. So basically the user must fill only ONE form and NOT both of them...SO basically if the user fills up form number 1, the validation will be on form 1 ONLY..

Below please find the code of both forms:开发者_C百科

    <form action="/registration.flow" method="post"  id="formElem1"  name="formElem1" autocomplete='off'>
  <label for="Name_First">First Name:</label>
  <input type="text" name="Name_First" id="Name_First" value="" class="required" maxlength="128"  />
  <label for="Name_Last">Last Name:</label>
  <input type="text" name="Name_Last" id="Name_Last" value="" class="required" maxlength="128" />

  <button id="registerButton" type="submit">Register</button>
</form>


<form action="/registration.flow" method="post"  id="formElem2"  name="formElem2" autocomplete='off'>
  <label for="Name_First">First Name:</label>
  <input type="text" name="Name_First" id="Name_First" value="" class="required" maxlength="128"  />
  <label for="Name_Last">Last Name:</label>
  <input type="text" name="Name_Last" id="Name_Last" value="" class="required" maxlength="128" />

   <button id="registerButton" type="submit">Register</button>
</form>

Can someone help me please?


You don't need jQuery specifically to do this. Simple javascript is fine. Call a separate function for the onSubmit of each form.

onSubmit="return validateForm1(this);"
  • and -

    onSubmit="return validateForm2(this);"

Make sure you return true or false depending on if the form passed or failed the validation.


I recommend you the jquery validator . It's easy to use and you can do the two validations separately.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜