jQuery dynamic validation

Posted by kpomka on Stack Overflow See other posts from Stack Overflow or by kpomka
Published on 2010-04-22T14:14:00Z Indexed on 2010/04/22 15:43 UTC
Read the original article Hit count: 192

Filed under:

Hi there Im trying to do a few things with jQuery validation plugin and seems stuck on one place.

Here is some code:

<script type="text/javascript">
    $(document).ready(function(){
        $('#myform').validate();
        $('#email').rules('add', {required: true, messages: {required: 'email is required'}} );
        $('#phone').rules('add', {required: true, messages: {required: 'phone is required'}} );
        $('#validate').click(function(){
            $('#result').text($('#myform').validate().form());
            return false;
        });
    });
</script>
<form id="myform">
<div>email:<input type="text" id="email" /></div>
<div>phone:<input type="text" id="phone" /></div>
<div id="result"></div>

<input id="valdate" type="image" src="images/submit.png" />
</form>

As a result i keep getting a wrong error message. If i click on submit button 'phone is required' is shown near email input and 'email is required' isnt shown at all.

Whats wrong with this code ?

© Stack Overflow or respective owner

Related posts about jquery-validate