开发者

jquery validation change error message on dropdown change

I'm new to jquery, i'm using validation plugin from http://bassistance.de, so far is working fine, until certain page i need to change the error message on dropdown change, instead of submit button clicked.

Here is what i have in my error message part

messages: {

   txtLocation: {

     required: function(){ 
                    if($("select[name=selDelBasis] option:selected").text()=="C&F FIFO" || $("select[name=selDelBasis] option:selected").text()=="CIF FIFO")
                        return "Please enter the name of discharge port.";
                    else
                        return "Please enter the name of port from where you will load your coal.";
            }},

In my html i have a select with name=selDelBasis and an input type text name="txtLocation"

To populate the problem here is the step.

1. Choose C&F FIFO from selDelBasis dropdown

2. Click Submit, without filli开发者_如何学Gong the txtLocation

3. Error message appear as "Please enter the name of discharge port."

4. Change selDelBasis from "C&F FIFO" to "FAS"

5. The error message no changes, still same "Please enter the name of discharge port."

What i want is on step 5, the error message should change to "Please enter the name of port from where you will load your coal."

Thanks


I don't know if I understood well, but I guess that set onclick option would do what you want:

$(".selector").validate({
   onclick: false
})

Analogously there is also onkeyup and onfocusout options:

A complete list of options: http://docs.jquery.com/Plugins/Validation/validate#toptions


Hi i managed to found a solution on this question. I used one of the validation method which is showErrors().

So in my dropdown onchange event, i do this

validator.showErrors({"txtLocation": "Please enter the name of discharge port."});

while validator is var validator = $("#frmMarket").validate();

Thanks for all help, i hope this thread can help other that have the same question

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜