Where should I put that code line?

This is my JS:

<script type="text/javascript">
        // extend the current rules with new groovy ones

        $().ready(function() {
                var validator = $("#texttests").bind("invalid-form.validate",
function() {
                        $("#summary").html("Your form contains " +
validator.numberOfInvalids() + " errors, see details below.");

                }).validate({
                        errorElement: "div",
                        errorContainer: $("#warning, #summary"),
                        errorPlacement: function(error, element) {

                                 error.appendTo( 
element.parent("td").next("td") );
                        },
                        success: function(label) {
                                label.text("ok").addClass("success");
                        },
                        rules: {
                                fullname: {
                                        required:true

                                },
                                bd_yr: {
                                        required:true,
                                        digits: true
                                },
                                bd_month: {
                                        required:true,
                                        digits: true
                                },
                                bd_day: {
                                        required:true,
                                        digits: true
                                },
                                countrynr: {
                                      required: true,
                                      remote: {
                                        url: "/lib/checkmobilenr.php",
                                        type: "post",
                                        data: {
                                          mobilenr: function() {
                                            return $("#mobilenr").val();
                                          }
                                        }
                                      }
                                    },

                                mobilenr: {
                                      required: true,
                                          digits: true,
                                      remote: {
                                        url: "/lib/checkmobilenr.php",
                                        type: "post",
                                        data: {
                                          countrynr: function() {
                                            return $("#countrynr").val();
                                          }
                                        }
                                      }
                                    }

                                ,
                                city: {
                                                required:true,


                                        },
                                username: {
                                        required: true,
                                        minlength: 2,
                                        remote: "/lib/checkusername.php"
                                },

                                        password: {
                                                required: true,
                                                minlength: 5
                                        },
                                        password_confirm: {
                                                required: true,
                                                minlength: 5,
                                                equalTo: "#password"
                                        }

                        },
                        messages: {
                                                fullname: "Should be a first 
and last name",
                                                bd_yr: "Please enter your year 
of birth",
                                                city: "Please enter your 
city/home town",
                                                lastname: "Please enter your 
lastname",

                                                username: {
                                                        required: "Enter a 
username",
                                                        minlength: 
jQuery.format("Enter at least {0} characters"),
                                                        remote: 
jQuery.format("{0} is already in use")
                                                },
                                                mobilenr: {
                                                        required: "Enter your 
mobile number",
                                                        minlength: 
jQuery.format("Enter at least {0} digits"),
                                                        maxlength: 
jQuery.format("Not more then {0} digits"),
                                                        remote: 
jQuery.format("mobile number already registered")
                                                },
                                                password: {
                                                        required: "Please 
provide a password",
                                                        minlength: "Your 
password must be at least 5 characters long"
                                                },
                                                confirm_password: {
                                                        required: "Please 
provide a password",
                                                        minlength: "Your 
password must be at least 5 characters long",
                                                        equalTo: "Please enter 
the same password as above"
                                                },
                                                email: "Please enter a valid 
email address",
                                                agree: "Please accept our 
policy"
                                        }

                });


        });



</script>

On 18 Apr, 00:43, James <james.gp....@gmail.com> wrote:
> Try:
> $("#myform").validate(validation_options).form();
>
> You might need to add a condition check to make sure the form was
> submitted, since you probably don't want this code to run
> automatically on the initial form load before the user actually
> submitted the form for the first time.
>
> On Apr 17, 8:09 am, Skatan <i...@klejm.se> wrote:
>
>
>
>
>
> > I would like to validate my form with jQuery when the pages directly
> > when the page is loading without need of submit, keyup. This because I
> > want it to work togheter with a PHP/server script validation in the
> > next step, for saftey reason. So if the server side validation
> > redirect the user pack to the form with some error, the forms should
> > be value with the data and the error messages should be writen by the
> > jQuery script.
>
> > Is this crazy and works in some other way, please help me.
> > Thanks for the great work with this script!

Reply via email to