Solved

Help In Java Script validation

Posted on 2011-03-17
5
240 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:Shinesh Premrajan
Shinesh Premrajan 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:Shinesh Premrajan
Shinesh Premrajan 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

772 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