If you only do it when the field loses focus and is invalid, then you wont
loop. A loop will only occur if your just constantly putting focus back on
the field without chekcing it first.
Much better to do all fields onsubmit anyway.
use qforms from www.pengoworks.com

Russ Michaels
--
Satachi Internet Development
Tel: 0870 787 3610
Fax: 07092 212636
Tech Support: 0906 9607800
Regular Support: 07092 300330
website: www.satachi.com
---
To submit support requests, please visit our website and select
support/customer support ticket system.

-----Original Message-----
From: Aidan Whitehall [mailto:[EMAIL PROTECTED]]
Sent: 12 February 2003 11:58
To: [EMAIL PROTECTED]
Subject: [ cf-dev ] OT: Preventing infinite alert loop in form field
validation


Just gonna try this on CFDev cause this is urgent, you're fast off the
mark and JS-Jive are a sleepy lot...

If you're doing form validation in consecutive fields where the error
displays an alert and puts focus back on the offending field, what's the
"best" way of preventing the browser from getting into an infinite loop
where it keeps alerting the error message?

Not the real code, but the gist is something like this:


function(field) {
   if (isNaN(field.value)) {
      alert("Please enter a number.");
      field.focus();
   }
}

<input type="" onBlur="isNumber(this);">
<input type="" onBlur="isNumber(this);">


If neither of the fields have content, you
 - tab off field one
 - focus goes to field two
 - validation for field one kicks in, alerts the error and puts focus on
field one
 - the onBlur event on the second field fires
 - which fails the validation test, putting focus on field one, ad
nauseam.


Thanks!

--
Aidan Whitehall <[EMAIL PROTECTED]>
Macromedia ColdFusion Developer
Fairbanks Environmental Ltd  +44 (0)1695 51775

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]


-- 
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

Reply via email to