Re: form validation

by "apathetic" <tmbkr(at)apatheticgenius.com>

 Date:  Sat, 22 Dec 2001 13:35:44 -0000
 To:  <magic32(at)jps.net>,
<hwg-techniques(at)mail.hwg.org>
 References:  rog
  todo: View Thread, Original
if( isFilled( form.address ) == false && form.want_newsletter.checked ==
true ) {

or you should be able to use:

if( !isFilled( form.address ) && form.want_newsletter.checked ) {

hth,
tim




www.ApatheticGenius.com
----- Original Message -----
From: "Roger Harness" <magic32(at)jps.net>
To: <hwg-techniques(at)mail.hwg.org>
Sent: Saturday, December 22, 2001 8:05 AM
Subject: form validation


> Ok folks, I should be able to figure this out by myself, but I'm not
having
> much luck.
>
> NOT being a javascript expert, i've pretty much taken this code directly
> from a jscript book, and successfully made it mine. It works perfect,
until
> I tried to get it to check for a selected radio button (the last if
> statement). I'm sure my syntax isn't correct (obviously), but i've tried
> every combination to check for that empty address field AND for a "yes"
> checked radio button.
>
> Here's the radio button info (and i know...font tags are bad...im behind
the
> times, please ignore):
>
>     <tr>
>       <td colspan="2"><font face="verdana, arial"
> size="2"><strong>&nbsp;&nbsp;Would you like to receive our
> newsletter?</strong></font></td>
>       <td><input type="radio" name="want_newsletter" value="yes"
checked>yes
> <input type="radio" name="want_newsletter" value="no">no</td>
>     </tr>
>
> and here is my javascript:
>
> <script language="JavaScript">
> <!--
> // CHECKS FOR NULL AND/OR EMPTY FIELDS
> function isFilled(elm) {
> if (elm.value == "" ||
>     elm.value == null)
> return false;
> else return true;
> }
> function isReady(form) {
> if (isFilled(form.first_name) == false) {
> alert("please enter your first name");
> form.first_name.focus();
> return false;
> }
> if (isFilled(form.last_name) == false) {
> alert("please enter your last name");
> form.last_name.focus();
> return false;
> }
> if (isFilled(form.T1) == false) {
> alert("please enter your phone #");
> form.T1.focus();
> return false;
> }
> if ((isFilled(form.address) == false) && (form.want_newsletter.checked ==
> 'yes')) {
> alert("please enter your address to receive newsletter");
> form.address.focus();
> return false;
> }
>
> return true;
> }
> //-->
> </script>
>
> Ive tried form.want_newsletter.checked ,
form.want_newsletter.checked.value
> , form.want_newsletter.value , etc etc etc. either errors, or just wont
> work.
>
> Any ideas?
>
> tia,
>
> Roger Harness

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA