1

I have syntax error in jQuery selector.I am add multiple rows using ajax and trying to validate it client side using validation.js..

In console, I see error

"SyntaxError: missing formal parameter".

$(document).ready(function(){
$( "#bookingadd" ).validate({

  $('input[type=text]').each(function(){

              $(this).rules( "add", "required");
          });

    $('select').each(function(){
              $(this).rules( "add", "selectsubservices"); // value is not 0
          });

  submitHandler: function (){  

    setTimeout(function(){}, 2000);

   jQuery("#bookingadd").submit();
  }

});

});

Using this code I validate textbox and dropdown

I added console screen enter image description here

3 Answers 3

1

Somewhere you are missing ")" or "}". Try to find out else You can save the

Sign up to request clarification or add additional context in comments.

1 Comment

He is not missing any braces or brackets. He is incorrectly sticking the .rules() method inside of the .validate() method, where the latter is only supposed to get key:value pairs comprised of options that are provided by the developer.
0

Your attempt with the .validate() method:

$( "#bookingadd" ).validate({
    $('input[type=text]').each(function(){
        $(this).rules( "add", "required");
        ....

You cannot put an .each() function inside of .validate! You can only put a comma-separated list of key:value pairs comprised of options that are provided by the developer.

Also, the .rules() method is a stand-alone jQuery Validate method and would never go inside of another jQuery Validate method.

Your structure should look something more like this...

$(document).ready(function() {

    $( "#bookingadd" ).validate({
        submitHandler: function (form) { // <- you missed the 'form' argument
            ....
            form.submit(); // <- you can use the 'form' argument here
            /* you don't need the timer here,
            so if you remove it, then there is
            no point in having the 'submitHandler' at all,
            as 'form.submit()' is already the default.
            Just remove the 'submitHandler' entirely. */
        }
    }); // end .validate()

    $('input[type=text]').each(function() {
        $(this).rules( "add", "required");
    });

    $('select').each(function() {
        $(this).rules( "add", "selectsubservices"); // value is not 0
    });

});

DEMO: jsfiddle.net/r416reg6/

Comments

0

Modified my post after Sparky's remarks. I should have refered jquery validation options before posting.

Please refer his answer, I have modified my code accordingly:

$(document).ready(function(){
       $("#bookingadd").validate({
          submitHandler: function (form){  
             form.submit();
          }
       });
       $.each($('input[type=text]'),function(){
            $(this).rules( "add", "required");
       });
       $.each($('select'),function(){
             $(this).rules( "add", "selectsubservices"); // value is not 0
       });
});

1 Comment

You are incorrectly sticking the .rules() method inside of the .validate() method, where the latter is only supposed to get key:value pairs comprised of options that are provided by the developer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.