Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Error Trapping making sure field has a Number


Message #1 by "Wes Bowen" <wjbowen@i...> on Fri, 23 Feb 2001 14:45:05
This is a MIME message. If you are reading this text, you may want to 
consider changing to a mail reader or gateway that understands how to 
properly handle MIME multipart messages.

--=_1D46BC48.0F6E141B
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

How about this: it checks for a vaule, then if a number:

<script language=3D"JavaScript" type=3D"text/javascript"><!--
 function checkinput()
 {
  var error_string =3D "";
  if (window.document.newcustomergroup.customerclasscode.value =3D=3D "")
  {
   error_string +=3D "Please select the class from the pick list.\n";
  }
 
  if (window.document.newcustomergroup.category.value =3D=3D "")
  {
   error_string +=3D "Please select the category from the pick list.\n";
  }
 
  if (window.document.newcustomergroup.population.value =3D=3D "")
  {
   error_string +=3D "Please input the customer group population.\n";
  }

  if (window.document.newcustomergroup.connectionnumber.value =3D=3D "")
  {
   error_string +=3D "Please input the customer group connection.\n";
  }

  if (isNaN(window.document.newcustomergroup.population.value))
  {
   error_string +=3D "Population must be a number, please try again.\n";
  }
 
  if (isNaN(window.document.newcustomergroup.connectionnumber.value))
  {
   error_string +=3D "Connection must be a number, please try again.\n";
  }

  if (isNaN(window.document.newcustomergroup.meter.value))
  {
   error_string +=3D "Meter must be a number, please try again.\n";
  }

  if (error_string =3D=3D "")
  {
   return true;
  }
  else
  {
   error_string =3D "We found the following problems with your form: \n" + 
error_string;
   alert(error_string);
   return false;
  }
 }
 // -->
 </script> 

Then place the onsubmit function in your form as such:

 <form action=3D"<cfoutput>#request.home#customergroup/index.cfm?fuseaction
=3D#createorupdate#&customergroupid=3D#attributes.customergroupid#</cfo
utput>" method=3D"post" name=3D"newcustomergroup" onsubmit=3D"var 
the_result =3D checkinput(); return the_result;">



V/R

Bill Gunnell
Cold Fusion Design Consultant
Computer Consultants International
(xxx) xxx-xxxx


  Return to Index