By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

How to change focus?

P: 46
Hi

One of the web form has 3 dates fields: Date of form entry, date of diagnosis and date of death.

Date of form entry has future date validation done which I thought of extending to the other two date fields.

Code being used already:

Expand|Select|Wrap|Line Numbers
  1.     function checkFutureDate(day, month, year, formName)
  2.     {
  3.         if (year > <%=zYear%>)
  4.         {
  5.             alert("Year cannot be later than the current year.");
  6.             document.frmUser.date3.focus();
  7.             return false;
  8.         }
  9.  
  10.         else if ((month > <%=zMonth%>) && (year == <%=zYear%>))
  11.         {
  12.             alert("Month cannot be later than the current month.");
  13.             document.frmUser.date2.focus();
  14.             return false;
  15.         }    
  16.  
  17.         else if ((day > <%=zDay%>) && (month == <%=zMonth%>) && (year == <%=zYear%>))
  18.         {
  19.             alert("Day cannot be later than the current day.");
  20.             document.frmUser.date1.focus();
  21.             return false;
  22.         }
  23.  
  24.         return true;
  25.     }
  26.  
  27. its been called from another function:
  28.  
  29. var ok = checkFutureDate(document.frmUser.date1.value, document.frmUser.date2.value, document.frmUser.date3.value);
  30.  
  31.         if(!ok)
  32.             return false;
  33.  
  34.  
I just thought I will use the same code with my date values:

Expand|Select|Wrap|Line Numbers
  1. var ok = checkFutureDate(diagdate1, diagdate2, diagdate3);
  2.     if(!ok)
  3.             return false;
  4.  
  5.             var ok = checkFutureDate(death1, death2,death3); 
  6.  
  7.         if(!ok)
  8.             return false;
  9.  
  10.  
It validate fine but the error message is vague and also the focus just returns to the date of form entry: date3 / date 2 or date1

Help I need?

Please tell me how can I provide a customized error message such that if the future date value if for date of entry it says: Your day value for date of entry (Similarly replace it with date of diagnosis/ date of death as applicable) can not be later than today's day.

Secondly, to return the focus, to the exact field that is wrong.

Can I pass the field values as variables and pass them instead of a fixed date1, date2 or date3 in the function that is validating for future value?

Hope I am clear, otherwise please let me know.

Thanks for your help in advance,
Sree
May 26 '08 #1
Share this Question
Share on Google+
2 Replies


hsriat
Expert 100+
P: 1,654
Hey Sreemati, could you please explain it properly?..

I could not understand what's not working, and what do you want to achieve.In function checkFutureDate, there is an argument formName, which is never used. And when it finds an invalid entry, it returns focus of the date1,2,3 accordingly. So where is the problem?

Regards,
Harpreet
May 26 '08 #2

acoder
Expert Mod 15k+
P: 16,027
Rather than pass values, pass a reference to the text field objects to the function. This will allow you to change focus to those elements when there's an error. The values are easy to retrieve using the value property. Change the focus() statements to use the arguments of the function. If you have trouble implementing this, post your attempt here.
May 26 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.