简体   繁体   English

javascript验证

[英]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. 我在javascript验证条件中面临一些问题,我需要更新文本框中的日期,并且该日期不应从applicationdate追溯,如果我将日期从applicationdate更新为backdate,则会收到警告信息masg E-CLRDATELTTXNDATE。问题是,如果我单击链接到该日期文本框的任何文本框,即使单击此警报窗口的“确定”按钮,此警报也会继续重复。

   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: 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. 这是因为您在警告错误消息之前调用了.focus()事件。 Place it after alert call. 将其放在警报电话之后。

Field receives focus then loses it on alert, blur event fired again on not changed data. 字段接收焦点,然后在警报上失去焦点,对未更改的数据再次触发模糊事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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