473,471 Members | 4,687 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to change focus?

46 New Member
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
2 1655
hsriat
1,654 Recognized Expert Top Contributor
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
16,027 Recognized Expert Moderator MVP
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

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

Similar topics

2
by: fish | last post by:
Hi, I have an HTML page with a FORM and some input fields. On the fields I wish to do validation as the punters change the field values. If they get it wrong, then I tell them and then wish...
6
by: Brian | last post by:
I'm trying unsuccessfully to use a variable in a script that changes focus. Depending on which link a user follows (navigates via keyboard or clicks), I'd like to change the focus to an input...
3
by: bunch92 | last post by:
Hi guys The code below will be used to fill in a crossword grid. When a user types a letter, focus is changed to next cell in the grid. My code doesn't work and I would be grateful if you...
3
by: GBW | last post by:
I'm new to VB .NET development - I'm trying to create a text box that as soon 3 characters are entered the focust will then move to the next text box I've tried using MaxLength or...
0
by: Wayne Wengert | last post by:
I have a form on which I change background colors when textbox get focus and I reset the background color when it loses focus. This works fine except when I change the focus via code. If I validate...
5
by: cj | last post by:
..net 2003 I have a form with 1 button and several labels on it. I don't want the button to be the default if enter is pressed. I want the user to have to actually click it for it to work. I...
4
by: Jon Slaughter | last post by:
I've created some custom controls and forms that allow the feature to temporarily transfer focus to a control that has been entered by the mouse. Everything seems to work fine but the problem I...
3
by: viral123 | last post by:
Hi all, does any one know how to get the functionality of get focus and lost focus using ASP.Net like VB.Net I want to change the textbox back ground color when it has the focus. I used...
10
by: engteng | last post by:
When textbox properties enable = False the font in the textbox become gray color. How do I change the gray color to black color ? Regards, Tee
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.