Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Help In Java Script validation

Hello experts,

I am facing issue in javascript validation. The requirement is that  I
 need to update the date in a textbox and that date should not be backdated
from the application date. If I update the date as backdate from the applicationdate
i will get the alert message "E-CLRDATELTTXNDATE" which is fine.  The issue is that if I click on any text box linked to that date text-box, this alert message is keep on repeating even after clicking on ok button in alert window.

I want this alert window go away after clicking on Ok button and focus should remain on same text field, how can i achieve this ?? Please suggest.

I am here attaching code for your reference.


<%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%>


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;
                    }
                   
                    }

                }

            }

Open in new window

0
sudhirgoogle
Asked:
sudhirgoogle
  • 3
  • 2
3 Solutions
 
Shinesh PremrajanEngineering ManagerCommented:
Update your function with a return statement, as mentioned in the below code
if (strWarning!="W")
      //Error
      {
            if ((strPrefix!="") && (strSuffix!=""))
                  alert(strErrMsgErrorCode+ ": " + strPrefix + " " +  strErrorDesc + " " + strSuffix );      
            else if ((strPrefix =="") && (strSuffix!=""))
                  alert(strErrMsgErrorCode+ ": " +  strErrorDesc + " " + strSuffix);
            else if ((strPrefix !="") && (strSuffix==""))
                  alert(strErrMsgErrorCode+ ": " + strPrefix + " " + strErrorDesc );
            else
                  alert(strErrMsgErrorCode+ ": " +  strErrorDesc );

          return false; //this is added
      }

Open in new window

0
 
sudhirgoogleAuthor Commented:
hI
I've  added the return false statement in the GetAlertMessage function.And in the mail function i gave as return GetAlertMessage("E-CLRDATE","E","","","") in all the places as u said.In this case my alert box is repeating infinite times.but if i add the document.frmPaymentClearing.txtClearingDate(i).focus() after the alert message,alert window is not repeating but the focus is not working.i tried by removing the below increment operation,in that case alert message is not repeating but focus is going to the previous textbox.
i guess problem is with this increment operation.i tried with different combination of this increment operation can u suggest me on this.
i++;
                    if (!isClearingDateGreaterThanTxnDate(i--))
                    {
                        document.frmPaymentClearing.txtClearingDate().focus();
                       
                        GetAlertMessage("E-CLRDATELTTXNDATE","E","","","");
                       
                    }

0
 
Shinesh PremrajanEngineering ManagerCommented:
I think the better option to use here is "this", instead of i. and incrementing and decrementing it.

onblur="txtClearingDate_blur((<%=i%>))">

should be

nblur="txtClearingDate_blur(this)" >

So the function will become

function txtClearingDate_blur(val){

alert(val.value); // if you need to refer the value in the object.
}

Hope this helps
0
 
sudhirgoogleAuthor Commented:
sfg
0
 
sudhirgoogleAuthor Commented:
I was not to able verify it. anyways thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now