2

Using the jQuery Validation plugin and AJAX, how can I validate the contents of say an input (textbox) but pass more than one parameter to a controller action?

A brilliant example of passing a single value via AJAX using the plugin can be found here.

3 Answers 3

3

Looking at the code for jQuery Validation it looks like the post data can not be customized. So you'll have to stick with query parameters:

 <script type="text/javascript">
$(document).ready(function(){
  $("#form-sign-up").validate(
  {
    var param1 = $('#mytextbox').val();

    rules:
    {
        login:
        {
          required: true,
          remote: '<%=Url.Action("IsLoginAvailable", "Accounts") %>?param1=' + param1
        }
      }  
    });

});
</script>
0

Something like this?

$(document).ready(function(){
  $("#form-sign-up").validate( {
    rules: {
      email: {
        required: true,
        email: true
      },
      surname: {
        required: true,
        surname: true
      }
    },
    messages: {
      email: {
        required: "Please provide an email",
        email: "Please provide a valid email"
      },
      surname: {
        required: "Please provide a surname",
        surname: "Please provide a valid surname"
      }
    }
  });
});

edit found a large demo here

1
  • The problem I have is that based on the user-name and the value of a hidden field goes into making a unique pair. So when validating the login name I need to pass both the login name and the hidden field value to an action. If you check the example in the question you'll see what I mean.
    – Kieron
    Dec 2, 2008 at 16:56
0

The correct Script will be

remote: function() { var p = $j('#productName').val(); return "../Product/LookupRevision?p=" + p; } instead of

remote: "../Product/LookupRevision"

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.