jQuery - Dynamically adding validation rule to multiple textboxes

Posted by Justin on Stack Overflow See other posts from Stack Overflow or by Justin
Published on 2010-06-14T02:11:33Z Indexed on 2010/06/14 2:22 UTC
Read the original article Hit count: 585

Filed under:

Hey, I'm trying to add a validation rule to multiple textboxes dynamically. Here's the js:

            //validate form.
            $("#SubmitForm").validate();
            $("input[id*=Hours]").rules("add", {
                number: true,
                messages: {
                    number: "Please enter a valid Hours"
                }
            });

This applies the rule to the very first textbox on the page with "Hours" in the id but then it doesn't apply it to any of the other ones.

Anyone know what's wrong here?

Thanks, Justin

© Stack Overflow or respective owner

Related posts about jQuery