April 11, 2012

Jquery form validation – pop up to specific checkbox

Question by holian

I use Jquery form validation. Before visitor submit i need to check the ‘Terms&Cond’ checkbox. If not checked i would like to see the message an alert box. (other messages shown near in the textboxes)

How to set this? I try this:

 $("#myform").validate({
      errorPlacement: function(error, element) {
            if ( element.is(":checkbox") ) {
                alert(error.html());
            }
            },
        rules: {
            name: {
                required: true,
                minlength: 3,
                maxlength: 40,
                lettersonly: false
            },
            ad: {
.....

But this did not work.

Thank you for help.

Answer by Starx

error does not have a html() function. You were probably trying to alert the markup of the element.

alert(element.html());

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!