简体   繁体   中英

javascript validation

I am facing some problem in javascript validation condition is I need to update the date in a textbox and that date should'nt be backdated from the applicationdate, if I update the date as backdate from the applicationdate ill get the alert masg E-CLRDATELTTXNDATE.issue is if I click on any text box linked to that date textbox this alert is keep on repeating even if I click on ok button of this alert window.

   function txtClearingDate_blur(i) {
        i--;
        if (document.frmPaymentClearing.hidTxnCount.value == 1) {
        if (("" + document.frmPaymentClearing.txtClearingDate.value).length > 0) {
                    if (!isDate(document.frmPaymentClearing.txtClearingDate.value,document.frmPaymentClearing.hidShortDateFormat.value,document.frmPaymentClearing.hidDateSeperator.value)) {
document.frmPaymentClearing.txtClearingDate.focus();return;
                         } else {
                                i++;
                    if (isClearingDateGreaterThanAppdate(i--)) {
                                        document.frmPaymentClearing.txtClearingDate.focus();
                        GetAlertMessage("E-CLRDATE","E","","","");
                     }
                                 i++;
                    if (!isClearingDateGreaterThanTxnDate(i--)) {
                        document.frmPaymentClearing.txtClearingDate().focus();

                        GetAlertMessage("E-CLRDATELTTXNDATE","E","","","");

                    }


                    }
                }
            } else {
                if (("" + document.frmPaymentClearing.txtClearingDate[i].value).length > 0) {
                    if (!isDate(document.frmPaymentClearing.txtClearingDate[i].value,document.frmPaymentClearing.hidShortDateFormat.value,document.frmPaymentClearing.hidDateSeperator.value)) {
                                       document.frmPaymentClearing.txtClearingDate[i].focus();return;
                                } else {
                                        i++;
                    if (isClearingDateGreaterThanAppdate(i--)) {
                                                   document.frmPaymentClearing.txtClearingDate[i].focus();
                               GetAlertMessage("E-CLRDATE","E","","","");
                    }

                    i++;
                    if (!isClearingDateGreaterThanTxnDate(i--)) {
                        document.frmPaymentClearing.txtClearingDate(i).focus();
                        GetAlertMessage("E-CLRDATELTTXNDATE","E","","","");
                        return;
                    }

                    }

                }

            }
        }

HTML:

<%If strFormState = "NEXTDISPLAY" Then%>
<INPUT type="text" name="txtClearingDate" size=10 value='<%=FormatDateTime(IIF(IsDBNull(rstPaymentRecs.fields.Item("ClearingDate").Value), Nothing, rstPaymentRecs.fields.Item("ClearingDate").Value), 2)%>' onblur="txtClearingDate_blur((<%=i%>))">
<INPUT type="hidden" name="hidTxnDate" size=10 value='<%=FormatDateTime(IIF(IsDBNull(rstPaymentRecs.fields.Item("TransactionDate").Value), Nothing, rstPaymentRecs.fields.Item("TransactionDate").Value), 2)%>'">
<%Else%>
<INPUT type="text" name="txtClearingDate" size=10 value='<%=FormatDateTime(objSecurityContext.Appdate, 2)%>' onblur="txtClearingDate_blur(<%=i%>)">
<INPUT type="hidden" name="hidTxnDate" size=10 value='<%=FormatDateTime(IIF(IsDBNull(rstPaymentRecs.fields.Item("TransactionDate").Value), Nothing, rstPaymentRecs.fields.Item("TransactionDate").Value), 2)%>'">
<%End If%>

It's because of .focus() event you call before alerting error message. Place it after alert call.

Field receives focus then loses it on alert, blur event fired again on not changed data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM