473,408 Members | 2,813 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,408 software developers and data experts.

Javascript and Form Processing

I wish to carry out standard form validation (i.e. is it a date?, is
there a value in the field, is it a number) using the onBlur event
rather than the onSubmit event. This (of course) leads to problems when
cancelling an edit as leaving a field to press the cancel button will
trigger the onBlur event and therefore the field validation. Is there
any way to know the destination field / button that caused the onBlur
event? In Ingres ABF/W4GL (mid eighties language of similar
functionality to javascript) there was an available attribute called
the targetfield so the code could run...

onBlur myfield =
{
if (targetfield != CancelButton) {
carry out validation
}
}

Is there something similar in javascript or will I have to program
round the houses i.e. onBlur records which validation to run and
onFocus runs the validation (unless it's a cancel button)?
TIA Bill

Oct 12 '05 #1
5 1906
billa wrote:
I wish to carry out standard form validation (i.e. is it a date?, is
there a value in the field, is it a number) using the onBlur event
rather than the onSubmit event.
You should not rely on onblur, its behaviour differs markedly across
browsers. In some browsers, the onclick is processed before the
onblur, in others it is after. In other browsers, clicking on a
button will not fire the onblur at all - the text input doesn't loose
focus.

If the field doesn't get focus, your validation doesn't run. To fix
your problem, make the onblur validation write an error message to the
page near the input field. Don't be tempted to trap the user in the
field by constantly returning focus to it until it passes validation -
that only annoys those who want to fill in other parts of the form and
return to the field to fix it later.

Run the validation onsubmit as well (just in case the date field was
never given focus).

Now if the onblur validation presents an error message at any time,
the flow of the page is not interrupted and the user has control of
when the error is fixed.
This (of course) leads to problems when
cancelling an edit as leaving a field to press the cancel button will
trigger the onBlur event and therefore the field validation. Is there


That does not happen in all browsers, and because of the different way
events are handled in different browsers (and probably different
versions of the same browser), you can't reliably determine what
caused the onblur to fire.

[...]

--
Rob
Oct 12 '05 #2
On 12/10/2005 13:38, billa wrote:
I wish to carry out standard form validation [...] using the onBlur
event [...]
The blur event is often not a good idea. It will fire /every/ time the
user tries to leave a control and, if you're showing error messages for
failed validation, this can seriously annoy users. Use the change event
/and/ the submit event.

[snip]
Is there any way to know the destination field / button that caused
the onBlur event?


No, there isn't. Sorry.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Oct 12 '05 #3
Lee
billa said:

I wish to carry out standard form validation (i.e. is it a date?, is
there a value in the field, is it a number) using the onBlur event
rather than the onSubmit event. This (of course) leads to problems when
cancelling an edit as leaving a field to press the cancel button will
trigger the onBlur event


Don't use onBlur for validation. Use onChange.
There are far too many things that can cause a field to lose focus
before the user is finished entering data.
Using onChange would also allow the onClick handler of your cancel
button to disable your validation.

Oct 12 '05 #4
In article <RE*******************@text.news.blueyonder.co.uk> , Michael Winter
says...

On 12/10/2005 13:38, billa wrote:
I wish to carry out standard form validation [...] using the onBlur
event [...]


The blur event is often not a good idea. It will fire /every/ time the
user tries to leave a control and, if you're showing error messages for
failed validation, this can seriously annoy users. Use the change event
/and/ the submit event.

[snip]
Is there any way to know the destination field / button that caused
the onBlur event?


No, there isn't. Sorry.

[snip]

Mike


Could you use a hidden form field and change its value (e.g.
document.FormName.HiddenFieldname.value = 'true') with the onBlur event?

Marty
--
Basic Newsguy 3 GB / month $39.95 / year
http://newsguy.com/overview.htm

Oct 12 '05 #5
Lee
Marty said:

In article <RE*******************@text.news.blueyonder.co.uk> , Michael Winter
says...

On 12/10/2005 13:38, billa wrote:
I wish to carry out standard form validation [...] using the onBlur
event [...]


The blur event is often not a good idea. It will fire /every/ time the
user tries to leave a control and, if you're showing error messages for
failed validation, this can seriously annoy users. Use the change event
/and/ the submit event.

[snip]
Is there any way to know the destination field / button that caused
the onBlur event?


No, there isn't. Sorry.

[snip]

Mike


Could you use a hidden form field and change its value (e.g.
document.FormName.HiddenFieldname.value = 'true') with the onBlur event?


I don't understand what you're suggesting?
Why a hidden form field instead of a Javascript variable, and
more importantly, how is that going to tell him which control
has focus?

Oct 12 '05 #6

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

Similar topics

3
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
6
by: Marios Koumides | last post by:
I have a page written in ASP and I added some Javascript code to ensure the input boxes are filled with correct data. That check is performed every time the user moves out from a textbox. Now right...
3
by: nazim | last post by:
Hi, As a real novice trying to get to grips with c#.NET and html. I have created a simple showdialogbox which is called from within a webpage.aspx, I pass values to it from the main page and i...
4
by: Greg | last post by:
I'm guessing the problem I'm having has something to do with Master Pages or DetailsView because the exact same code works fine on a page without a Master Page and DetailsView controls. The...
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...
0
by: pbd22 | last post by:
Hi. I am having a really tough time here and would appreciate some help. i am using an iFrame to pass a url string of files to upload to server. on the client i have created a multiple...
84
by: Patient Guy | last post by:
Which is the better approach in working with Javascript? 1. Server side processing: Web server gets form input, runs it into the Javascript module, and PHP collects the output for document prep....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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.