views:

485

answers:

3

I have multiple section is asp.net that submits data in chunk and i want to use jquery validation plugin, but issue is that asp.net wraps everything in form and child forms not wokring right and technically incorrect.

So only alternative is forget about form and implement validation for divs. But all sames i see are using form. As not being not good at jquery i can't figure out how to use this validator on section of page(On div).

Is it possible? or any other good alternative?

Source: http://bassistance.de/jquery-plugins/jquery-plugin-validation/

+1  A: 

I am using bassistance jquery plugin that you mentioned above, and it doesnt require form submmission to do validation. it just validated after "on blur" event triggered.

or if you want to validate it manually you can call like : $("#commentForm").validate(); (read on this doc page [http://docs.jquery.com/Plugins/Validation][1])

nightingale2k1
+4  A: 

Like nightingale2k1 said, you should be able to use that plug-in just fine with a FORM. Here's a quick example that uses a DIV instead:

<div id="pseudoForm">
  <input type="text" name="first_name"/>
  <input type="text" name="last_name"/>
</div>
<script type="text/javascript">
  $("#pseudoForm").validate({
    onfocusout:true,
    rules:{
      first_name:"required",
      last_name:"required"
    });
</script>

Notice how I used "onfocusout:true", which will make the plug-in validate when the user de-selects either element. You'll need to either use something like that, or else hook up your own event (probably in response to a button press) for the validation to be triggered, as the normal trigger (onSubmit) isn't applicable to DIVs.

machineghost
+1  A: 

In one of my pages I have a div that is sumitted back via Java and Ajax. Prior to submitting, I validate the individual fields using .validate().element( "#myelement" ); I do it all in javascript though, and don't rely at all on the built in automagic asp controls.

I hate to say it, but that global form issue is your real problem. It's probably not an option, but if it is, look as switching to asp.net MVC.

Russell Steen
Thanks for your response i have switched application to MVC to get more control and clean html
mamu