"This" might help. ;-)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script language="javascript">
function textValidate(field) {
if (field.value.length == 0) {
alert("Please enter some text in " + field.name);
return false;
}
}
</script>
</head>
<body>
<form>
Field 1: <input type="text" name="field1" onBlur="textValidate(this);"
/><br />
Field 2: <input type="text" name="field2" onBlur="textValidate(this);"
/><br />
</form>
</body>
</html>
Bear in mind that if you're checking to see if the user entered
anything at all, you also need to handle if they just enter spaces,
which a length check won't catch. I have an "isBlank" function laying
around somewhere that checks both length and checks for space
input--let me know if you're interested in that and I'll dig it up.
Matt
On Tue, 4 Jan 2005 08:31:42 -0600, Alford, Gary L
<[EMAIL PROTECTED]> wrote:
> Happy New Year!
>
> Excuse me for going a little off topic, but I am a bit confused...
>
> Please consider the following:
>
> <html>
> <head>
> <title>Untitled</title>
> <script language="JavaScript">
> <!--
> function _validateText1() {
> var validate = document.form1.text1.value;
> if (validate.length < 1) {
> window.alert("Please enter a value
> for Text 1.");
> }
> }
> function _validateText2() {
> var validate = document.form1.text2.value;
> if (validate.length < 1) {
> window.alert("Please enter a value
> for Text 2.");
> }
> }
> // -->
> </script>
> </head>
> <body>
> <form name="form1">
> <input type="Text" name="text1" onblur="_validateText1()">
> <input type="Text" name="text2" onblur="_validateText2()">
> </form>
> </body>
> </html>
>
> Is there a way to dynamically send the form name and input box name to the
> JavaScript functions as variables so I only have to write one function that
> would validate all input text boxes in the form? Is there a better way to
> do an input validation on an "onblur" event that what I am trying to do? Is
> there a CF tag that can perform this same function easier on an "onblur"
> event? I know I can use <cfform... and <cfinput... and specify the required
> attribute, but this only appears to validate upon form submittal and it is
> requested to perform this validation on a blur event - prior to form
> submittal.
>
> Any help would be appreciated.
>
> _____
>
> Gary L. Alford
> Manufacturing Operations Project Specialist
> Bell Helicopter XWorx
> Phone: (817) 280-6233 Fax: (817) 278-6233
> [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
>
> I have not failed. I've found 10,000 ways that won't work.
> Thomas A. Edison
> _____
>
> ----------------------------------------------------------
> To post, send email to [email protected]
> To unsubscribe:
> http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
> To subscribe:
> http://www.dfwcfug.org/form_MemberRegistration.cfm
>
>
--
Matt Woodward
[EMAIL PROTECTED]
http://www.mattwoodward.com
----------------------------------------------------------
To post, send email to [email protected]
To unsubscribe:
http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
To subscribe:
http://www.dfwcfug.org/form_MemberRegistration.cfm