0

Actually I am a new user of LAMP(Linux, Apache, Mysql, PHP). I have created a web page using php scripts and have used sort of validation rules by js validation plugin to validate form inputs (textbox, email etc).

  • I have created 2 dropdown list .

    • (a) "Category" contains options as Child,Adult

    • (b) "Seat" contains options as NON-AC,AC

  • Then I have used a text box: "Amount" which receives input as integer. The conditions are

    • child & Non-AC - 150 (as Amount)

    • Child & AC -200 (as Amount)

    • Adult & Non-AC - 300 (as amount)
    • Adult & AC - 400 (as amount)

I have to validate Amount textbox by considering the inputs form both the dropdown list.

I have searched for jquery validation.js and found the min constraint. but didn't get way to custom validation code to validate textbox using min and input from the dropdown list.

I will be very thankful , if someone helps me out.

4

2 回答 2

1

您可以编写自己的验证方法,如下所示

jQuery.validator.addMethod(
    "amountcheck",
    function(value,element){
         // value ==> the value of text box , element ==> the text box
         var category = $("#category").val();
         var seat = $("#seat").val();   
         // check it's valid or not..
         if (true){
              return this.optional(element) || true;
         }else{
              return this.optional(element) || false;
         }
    },
    "Invalid Amount"
);

然后

$(form).validation({
    rules:{
        Amount:{
             amountcheck:true
        }
    }
})
于 2012-04-27T06:50:18.253 回答
0

尝试这样做:---

jQuery('#Category).change(function() {
    //ur code comes here..
    //here you can give ur condition based on category changed..
});
于 2012-04-27T06:52:00.873 回答