Solved

Help In Java Script validation

Posted on 2011-03-17
5
236 Views
Last Modified: 2012-05-11
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
Comment
Question by:sudhirgoogle
  • 3
  • 2
5 Comments
 
LVL 17

Assisted Solution

by:shinuq
shinuq earned 500 total points
ID: 35154679
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
 
LVL 1

Accepted Solution

by:
sudhirgoogle earned 0 total points
ID: 35154848
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
 
LVL 17

Assisted Solution

by:shinuq
shinuq earned 500 total points
ID: 35154917
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
 
LVL 1

Author Comment

by:sudhirgoogle
ID: 35735770
sfg
0
 
LVL 1

Author Closing Comment

by:sudhirgoogle
ID: 35763287
I was not to able verify it. anyways thanks for your help.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now