473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Help w/ interactive form data validation

I'm writing a small ASP program which prompts the user for data. I
would like to interactively validate the data as they are entering it,
rather than waiting until they submit the form. So, I am doing
something like this (this is a very simple example):
<head>
<script language=javascript>

function validatefield1()
var i;
i = document.myForm.field1.value
if ( i < 10 or i > 20 ) {
alert("please enter a # between 10 and 20!");
document.getElementByID('field1').focus();
return false;
}
return true;
}

function validatefield2()
var i;
i = document.myForm.field2.value
if ( i < 20 or i > 30 ) {
alert("please enter a # between 20 and 30!");
document.getElementByID('field2').focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form name=myForm id=myForm method=post action='/nextpage.asp'>
Field1: <input type=text size=2 id=field1 name=field1
onblur='validatefield1();'>
Field2: <input type=text size=2 id=field1 name=field1
onblur='validatefield2();'>
</form>
</body>
Here is the problem:

By default the first field has focus. If I press tab to bypass it
without entering anything, focus shifts to field2 immediately. The
onblur event fires, which checks the value in field1, sees it is
invalid, so prints an error message and resets the focus to field2.

Naturally, this causes field2 to lose focus. This causes field2's blur
event to kick of, which causes an error (since the field is blank),
printing an error, setting focus back to field2.

The effect is an endless loop of error messages.

I've tried other combinations of events, such as ondeactivate, but they
all result in the same behavior.

Why does the focus shift from field1 to field2 prior to the onblur
event completing?

Can someone explain the proper sequence of event processing on ASP
forms? When I press tab in field1, why does focus shift to field2 prior
to the onblur event for field1 completing? I can't seem to find this
documented anywhere in the msdn documentation to explain how events are
sequenced on IIS forms.

Alternatively, can someone suggest which event I would use to
accomplish what I'm trying to do? I'd prefer to interactively validate
data, rather than waiting until the form is submitted which I think is
messy and unprofessional, compared to the VB apps I've written.

Thanks
Vin

Feb 24 '06 #1
2 1567
On 23 Feb 2006 16:47:04 -0800, "Vinny" <te*****@yahoo.com> wrote:
I'm writing a small ASP program which prompts the user for data. I
would like to interactively validate the data as they are entering it,
rather than waiting until they submit the form.


Can't in ASP. Client side code would be needed, until the form is
submitted the server can't respond.

Jeff
Feb 24 '06 #2

Vinny wrote:
I'm writing a small ASP program which prompts the user for data. I
would like to interactively validate the data as they are entering it,
rather than waiting until they submit the form. So, I am doing
something like this (this is a very simple example):
<head>
<script language=javascript>

function validatefield1()
var i;
i = document.myForm.field1.value
if ( i < 10 or i > 20 ) {
alert("please enter a # between 10 and 20!");
document.getElementByID('field1').focus();
return false;
}
return true;
}

function validatefield2()
var i;
i = document.myForm.field2.value
if ( i < 20 or i > 30 ) {
alert("please enter a # between 20 and 30!");
document.getElementByID('field2').focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form name=myForm id=myForm method=post action='/nextpage.asp'>
Field1: <input type=text size=2 id=field1 name=field1
onblur='validatefield1();'>
Field2: <input type=text size=2 id=field1 name=field1
onblur='validatefield2();'>
</form>
</body>
Here is the problem:

By default the first field has focus. If I press tab to bypass it
without entering anything, focus shifts to field2 immediately. The
onblur event fires, which checks the value in field1, sees it is
invalid, so prints an error message and resets the focus to field2.

Naturally, this causes field2 to lose focus. This causes field2's blur
event to kick of, which causes an error (since the field is blank),
printing an error, setting focus back to field2.

The effect is an endless loop of error messages.

I've tried other combinations of events, such as ondeactivate, but they
all result in the same behavior.

Why does the focus shift from field1 to field2 prior to the onblur
event completing?

Can someone explain the proper sequence of event processing on ASP
forms?


ASP is irrelevant in your context, and there is no such thing as an
"ASP" form. There is an HTML form, which you can use server-side ASP
to process, or you can use client-side javascript (or a mixture of
both).

In your case, you would be better off asking this question in a
client-side code newsgroup.

/P.

Feb 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
2
by: qsweetbee | last post by:
I have a form(fAddUsers) in my database. It is continue form for data entry. Some fields are required fields. Some are optional fields. There is 1 particular filed(TokenExpirationDate)on the form...
3
by: Earthling | last post by:
Any help would be appreciated to solve the following simple problem that I will describe. *** There is a form called "red chocolate form". The form has a particular subform field that has a...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
36
by: aljamala | last post by:
Hi, I keep getting this warning on a page, but I do not know what the problem is...does anyone have an idea about what could be wrong? line 88 column 7 - Warning: missing </formbefore <td> it...
2
by: rynato | last post by:
I have a form which the user fills out to enter some data. If there already exists an uncompleted session - say, the user started entering some data but had to stop to do something else - the...
6
by: smk17 | last post by:
I've spent the last few minutes searching for this question and I found an answer, but it wasn't quite what the client wanted. I have a simple online form where the user needs to fill out five...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.