Conflict between Server Control Verification and self-written JavaScript verification functions (requiredfieldvalidator & JS)

Source: Internet
Author: User

On a web page, I used the regularexpressionvalidator control to verify the textbox. Then I wrote another JS function to call the Click Event of the button. The following problem occurs:
1. Enter the textbox and click the button to trigger JS function verification.
2. You can trigger regularexpressionvalidator verification when entering textbox.
3. When the textbox input is obviously incorrect, clicking the button cannot trigger regularexpressionvalidator to verify the control on the page.

My JS functions are as follows:
Function check_value (FRM)
{
VaR condate1_frm.txt date. value;
Condate = condate. Replace (/-/g ,"\/");
VaR time0 = new date ();
VaR time1 = new date (condate );
VaR date0 = date. parse (time0 );
VaR date1 = date. parse (time1 );
If (date1> time0)
{
Alert ("the last contact date cannot be later than today's date. ");
Return false;
}
}
Then when I load the page:
Btnadd. attributes ["onclick"] = "javascript: Return check_value (" + this. ID + ");"; the problem lies in 3, and causesvalidation is true.

ModifyCodeTo solve this problem:
Btnadd. attributes ["onclick"] = "javascript:If (page_clientvalidate ())Return check_value ("+ this. ID + ");";

The preceding section added that if the requiredfieldvalidator control is verified, the JS function is called and the test is successful.

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.