3

I want to send an extra parameter to the validation server side script. I have this code:

$("#edit_info").validate({
                debug: false,
              rules: {
                name: {
                    required: true,
                    //remote: "validate.php",
                    remote: { url:"validate.php", async:false },
                    data: {'cat_id':'34'}
                    /*data: {
                      cat_id: function () { return '34'; }
                    }*/
                },

But only the name gets sent. Any idea why? Thanks!

2
  • What happens if you make cat_id a function instead? Like what you have commented out basically. Commented Dec 17, 2012 at 13:51
  • it's the same. Only the name is sent. I have no idea why Commented Dec 17, 2012 at 13:55

2 Answers 2

5

In case you want to send dynamic parameters, instead of static:

$("#edit_info").validate({
        debug: false,
      rules: {
        name: {
            required: true,
            remote: { 
                url:"validate.php", 
                data: {'cat_id':function(){return $('#otherelement').val()}},
                async:false 
            }
        },
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, but is there a way to pass the field name as a variable instead of a specific ID? $(this).val() didn't work.
it would be something like this: $('otherelement[name=foo]').val()
4

Found out what the problem was. data must be inside the remote tags...

$("#edit_info").validate({
            debug: false,
          rules: {
            name: {
                required: true,
                remote: { 
                    url:"validate.php", 
                    data: {'cat_id':'34'},
                    async:false 
                }
            },

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.