[thelist] Javascript if...or statement

Joshua Olson joshua at waetech.com
Fri Aug 30 10:13:01 CDT 2002


----- Original Message -----
From: "Stephen Caudill" <SCaudill at municode.com>
Sent: Friday, August 30, 2002 11:01 AM


> Here's a javascript question:
>
>   I am performing some validation on a form and want to make sure that at
least one of two select fields has been chosen between.  The select fields
are being generated via an array in ASP, one a product version and the other
a plugin version.  As this is a support request form, I need to ensure at
least one has been selected from.  Here's my attempt:
>
> <script type="text/javascript">
> function checksubmit()
> {
>       if
>   (document.Job.VersionType.value == "")
>   ||
>   (document.Job.LFproduct.value == "")
>    {
>       alert("Please select a Version or Plug-In")
>       document.Form.VersionType.focus()
>       return false
>    }
>    return true
> }
> </script>

That's basically correct, except that you want to use && instead of II if
you only want the alert if they don't enter either value.  The current code
will fire the alert if either is blank, not both are blank.  Then, just wrap
the whole if criteria in () and you should be okay.

-joshua

P.S.  As a shortcut, you could use:

if (document.Job.VersionType.value + document.Job.LFproduct.value == '')
{
  etc.
}

Do you see why this works too?




More information about the thelist mailing list