Solved

Help In Java Script validation

Posted on 2011-03-17
5
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET - Why is accordion not working? 3 50
Html date format 9 20
[form-control] Retain values after a POST action 21 37
Word Press Fixes to Google Speed Test Issues 2 25
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

726 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