Form validation help



A customer wants me to convert a VB app I wrote for them into a web app
for remote users to do data entry.

So, I'm writing a small ASP program which prompts the user for data,
much like a VB program. 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've read the newsgroup and people's
comments about not using the onblur event, but 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. Plus the customer wants me to keep the web page
operationally identical to the VB app, and the VB app validates data at
the point of entry.


Thanks
Vin

.



Relevant Pages

  • Re: Parser for CSV files
    ... debugged console app into a Windows Service, ... > and Write it somewhere as a CSV file ... Scrub / validate / log ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Error - Error Accessing File. Network Conn..." File Corruption?
    ... > consuming problem receiving the error message "Error Accessing File. ... > truly clean up an mdb? ... Sometimes the app ... > - Does anyone know of a good site dealing with Access file corruption? ...
    (microsoft.public.access.formscoding)
  • Re: ASP.NET Authentication
    ... The process hosting the web app must have at least read ACLs for the web ... I have to log into the server to see a more enlightening message than "Runtime error" and then being directed to change the customErrors mode to off to view the specific error message. ... to start monitoring file changes" blah, blah, blah. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: VB6 & Active Directory
    ... Actually, Mark, I'd completely missed the fact Ivan was already using the ... understood him to want to validate a given username + password pair inside ... VB6 - you're on your own if you choose to follow this route. ... A VB6 app must integrate with AD, ...
    (microsoft.public.vb.general.discussion)
  • Re: I get the message Microsoft Office 2000 premium error 1706
    ... installed any app it couldn't replace. ... which can generally indicate something is broken in the installation, ... I then get a further error message ... The MS office 2000 was on a home user license from my old employer. ...
    (microsoft.public.word.docmanagement)