0
$("#commentForm").validate({
            rules: {
                insurance1$ucBuildingInsurance$txtOtherReasonDescription: required
}
});

My current script looks like this to validate a textbox txtOtherReasonDescription.Ideally I would like to replace insurance1$ucBuildingInsurance$txtOtherReasonDescription with $() syntax so the control id is not hardcoded. Is there anyway this can be achieved?

1 Answer 1

1

You can add the rule using a selector like this:

$("#commentForm").validate();
$("input[id$='txtOtherReasonDescription']").rules("add", { required: true });

Since you're in ASP.Net, either id$= or name$= works here, but the concept is set up the valdiation on the form, then attach a rule to the matched elements using .rules("add", rulesToAdd).

Sign up to request clarification or add additional context in comments.

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.