<form onsubmit="return validate()"> will call your function when form is submitted, and return a value, returning false wills top form submititng.
-----Original Message----- From: Aidan Whitehall [mailto:[EMAIL PROTECTED]] Sent: 12 February 2003 13:07 To: [EMAIL PROTECTED] Subject: RE: [ cf-dev ] OT: Preventing infinite alert loop in form field validation > can u post the code? The two functions are taken from external javascript files. Thanks. <html> <head> <title></title> <script language="JavaScript" type="text/javascript"> <!-- // checkHasInteger() checks to see if the quantity is zero or a positive integer. If 'required' is set to true, // a value must be supplied; otherwise it will throw an error only if it's not zero or a positive integer. function checkHasInteger(field, required, message) { if (arguments.length == 3) var alertMsg = message; else var alertMsg = "Please enter a whole number."; switch(required) { case false: if (field.value.length > 0 && !isPositiveInteger(field.value)) { alert(alertMsg); field.focus(); } break; case true: if (field.value == null || field.value.length == 0 || !isPositiveInteger(field.value)) { alert(alertMsg); field.focus(); } break; } } // isPositiveInteger checks to see if the numeric argument is an integer >= 0. function isPositiveInteger(testNumber) { if (isNaN(testNumber) || testNumber < 0 || testNumber.indexOf(".") != -1) { return false; } else { return true; } } // --> </script> </head> <body> <form> <input type="Text" name="staff" value="" maxlength="4" onFocus="this.select();" onBlur="checkHasInteger(this, true);"> <input type="Text" name="customers" value="" maxlength="4" onFocus="this.select();" onBlur="checkHasInteger(this, true);"> </form> </body> </html> -- 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]
