> Has anyone created a form that does:
>
> Validation, where the formfield labels turn red when a field is
null?
> Is there an easier way?

You may want to try javaScript to validate before you send the form
off to the server.  This should solve your problem, unless I'm really
missing something.

The code below should do pretty much everything you want (dunno how it
works on Netscape, but that may just be a fiddle).  A lot of this
stuff can be rolled up into loops I'm sure.

Hope it helps.

Dan.

---------

<script language="JavaScript">
<!--
function checkForm()
{

  var showMessage = false;
  var missingText = '';

  if  (demo.password2.value.length == 0) {
    spanpassword2.style.color = "FF0000";
    demo.password2.style.background = "FF9999";
    demo.password2.focus();
    showMessage = true;
    missingText = 'Password 2 is missing\n' + missingText;
  }
  else {
    demo.password2.style.background = "FFFFFF";
  }


  if  (demo.password1.value.length == 0) {
    spanpassword1.style.color = "FF0000";
    demo.password1.style.background = "FF9999";
    demo.password1.focus();
    showMessage = true;
    missingText = 'Password 2 is missing\n' + missingText;
  }
  else {
    demo.password1.style.background = "FFFFFF";
  }


  if  (demo.lastName.value.length == 0) {
    spanlastName.style.color = "FF0000";
    demo.lastName.style.background = "FF9999";
    demo.lastName.focus();
    showMessage = true;
    missingText = 'Last Name is missing\n' + missingText;
  }
  else {
    demo.lastName.style.background = "FFFFFF";
  }


  if  (demo.firstName.value.length == 0) {
    spanfirstName.style.color = "FF0000";
    demo.firstName.style.background = "FF9999";
    demo.firstName.focus();
    showMessage = true;
    missingText = 'First Name is missing\n' + missingText;
  }
  else {
    demo.firstName.style.background = "FFFFFF";
  }

  if  (showMessage) {
    alert('Please fill in the missing fields\n' + missingText);
    return false;
  }

  if (demo.password1.value != demo.password2.value) {
    alert('Your passwords do not match, please try again');
    spanpassword1.style.color = "FF0000";
    demo.password1.style.background = "FF9999";
    demo.password1.focus();
    demo.password1.value = "";
    spanpassword2.style.color = "FF0000";
    demo.password2.style.background = "FF9999";
    demo.password2.value = "";
    return false;
  }


  demo.submit();
}
//-->
</script>

<form action="page2.cfm" method="post" name="demo"
onSubmit="checkForm()">
  <table>
    <tr><td><span id="spanfirstName" name="firstName" style="color:
000000">Firstname</span></td><td><input type="text" name="firstName"
style="background-color : FFFFFF"></td></tr>
    <tr><td><span id="spanlastName" style="color:
000000">Lastname</span></td><td><input type="text" name="lastName"
style="background-color : FFFFFF"></td></tr>
    <tr><td><span id="spanpassword1" style="color:
000000">Password</span></td><td><input type="text" name="password1"
style="background-color : FFFFFF"></td></tr>
    <tr><td><span id="spanpassword2" style="color:
000000">Verify</span></td><td><input type="text" name="password2"
style="background-color : FFFFFF"></td></tr>
  </table>
<span onclick="checkForm()" name="submitLink" style="color: FF0000;
text-decoration : underline; cursor: hand">Submit</span>
</form>

------



This message is intended only for the use of the person(s) ("the intended 
recipient(s)") to whom it is addressed.

It may contain information which is privileged and confidential within the meaning of 
the applicable law. 
If you are not the intended recipient, please contact the sender as soon as possible.
The views expressed in this communication may not necessarily be the views held by 
Live Information Systems Limited.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-community@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to