473,770 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1932
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.ne ws.blueyonder.c o.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.FormNa me.HiddenFieldn ame.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.ne ws.blueyonder.c o.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.FormN ame.HiddenField name.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
2304
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 need to: 1. Click a submit button on an asp page, calling another page that saves the contents of that form to a database and then displays
53
5745
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 difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
6
1415
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 before I submit the form to the server for processing, I want to make a final test on the values. <input type="submit" onClick="testResults(this.form)" value="Submit" > The problem here is that I make the check in the testResults function...
3
1888
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 also retrieve values from the ones entered in the dialog box: <script type="text/javascript">
4
8936
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 problem is, when the javascript fires on the txtDateRequiredOut TextBox in IE, I get "Error on Page" in the status bar and the error says: "Object Expected". Viewing the source of the page while running shows a link created properly for the linked...
27
4754
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 appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
0
1625
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 upload javascript using the below link: http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/
84
3970
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. 2. Client side processing: Web server gets form input and passes it to PHP which includes the Javascript written in a way to make the form input processed on the client side and rendered (probably using DOM function calls) on that side as...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10037
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
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.