[thelist] js testing for empty fields

.jeff jeff at members.evolt.org
Thu Feb 13 15:42:01 CST 2003


ben,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Ben Dyer
>
> > Well, if the user enters 0 (zero) then the above if
> > expression would evaluate as false in JavaScript, even
> > though the user indeed entered data, so I wouldn't
> > actually recommend this. :)
>
> Actually, I don't think that's true.  I just whipped up
> a quick test.
>
> [snip]
>
> When you submit, the only time the alert "test IS false"
> came up was when there was no value in the text field.
> A value of "0" correctly returned the "test IS true" box,
> as did anything else I entered: "1", "false",
> "ReiAyanami", etc.
>
> I only tested IE6/W2K, but I've never heard of it being
> the case to return false when the form field value is
> 0.  Perhaps I'm misunderstanding what you're suggesting.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

there's a reason it works this way -- form field values are strings and will
be evaluated as strings.  so, a "0" (zero) as a string is not the boolean
false, as might be thought.  it's not until you apply the parseInt() method
to it that it'll evaluate as a boolean false.

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/




More information about the thelist mailing list