[Javascript] combining if statements

charlie_chan charlie_chan at cox-internet.com
Fri Feb 7 11:31:11 CST 2003


If the -1 is a boolean, you should not place quotations marks around it.  By
putting quotations marks around it, you make it a string value.

If books1beg.value is a boolean variable:
if (openp5.books1beg.value ==-1){
K =Number(0);

or
 If books1beg.value is a text box entry:
if (openp5.books1beg.value ==" ") {
> >     K =Number(0);


----- Original Message -----
From: "Mike Ledig" <hobbes_tiger at gmx.de>
To: <javascript at LaTech.edu>
Sent: Friday, February 07, 2003 10:34 AM
Subject: Re: [Javascript] combining if statements


> Hello Cheryl,
>
>
> Cheryl Kirkpatrick schrieb:
> ...
>
>
> > if ((openp5.books1beg.value =="-1") == true) {
> >     K =Number(0);
> >    }
> > if (isNaN(openp5.books1beg.value) != true)
> > K = Number(openp5.books1beg.value);
>
> Here's your problem!
> You test first, whether openp5.books1beg.value is -1. If true, you put
> Number(0) in K, but then you test whether openp5.books1beg.value is a
> number or not. Well, -1 IS a number, so K becomes to
> Number(openp5.books1beg.value).
>
> I think you should take this if statement:
>
> if ((openp5.books1beg.value !="-1") && (!isNaN(openp5.books1beg.value)){
>     K = Number(openp5.books1beg.value);
> }else {
>     K =Number(0);
> }
> HTH and greetings
> Mike.
>
> --
> Training und Projekte
> http://www.gidel.de
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list