Enable and disable code for server validation controls based on jquery implementation _jquery

Source: Internet
Author: User

Application background

1. When the user needs to fill out the form.
2. The page uses server validation controls.
3. By the user to choose whether to fill out more items, more items display and hidden with display control, the following figure.

Click "Add Service Content" to display the new form item, as shown below.

Click "Cancel Add" to hide the new form item.

Problem: When the user clicks Next, does not validate the new area form of Display=none, when the user clicks "Cancel increases", disables the server validation control. Instead, enable the server validation control.

Solving method

Let's use jquery to get it done, mostly too.

1. Output the validation control to be disabled.

Copy Code code as follows:
var validatorcontrols = new Array (' Requiredfieldvalidatorname ', ' Requiredfieldvalidatorid ');


2. Disable validation by default.

Copy Code code as follows:
for (var i = 0; i < validatorcontrols.length i + +) {validatorenable ($ (' # ' + validatorcontrols[i]). Get (0), false);


3. When you click "Add Service Content", enable authentication.

Copy Code code as follows:
for (var i = 0; i < validatorcontrols.length i + +) {validatorenable ($ (' # ' + validatorcontrols[i]). Get (0), true);


4. It's done.

Summary

In fact, the core of the validatorenable () is the function. Sometimes looking at the examples may not really understand, only the real hands-on ability to have a more profound impression.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.