Re: NULL Values
by "Cyanide _7" <leo7278(at)hotmail.com>
|
Date: |
Thu, 23 Mar 2000 02:51:23 CST |
To: |
hwg-languages(at)hwg.org |
Cc: |
aneely(at)softouch.on.ca, Douglass.Franklin(at)ssa.gov |
|
todo: View
Thread,
Original
|
|
> How do I handle null values on input? My script accepts numeric values,
> > but
> > if I enter an alphabet character or let the form element remain null
> >>
> > TROUBLE...
first of all, do you want to accept them as zero? or prompt the user for
valid data?
>Accept numeric data only (JavaScript):
>Found this in a book somewhere - works fine.
>Called with an onChange="return isNumber(this)" in the form.
someone already went to the trouble of writing a better version of this
function, its called isNaN. that script would have choked on the decimal!
try this:
function checkValid(which){
valid = (isNaN(which.value));
if(!valid){
alert(which.value + " is not a valid number. Please try again.");
which.focus();
which.select();
}
return valid;
}
<form onSubmit="return checkValid(this['fieldName']);">
>Handling "NULL" values, I assume you mean "empty" fields?
the only input i can think of getting from a user where you'd get null is
from a prompt dialog box's cancel action. otherwise you may get undefined or
the empty string as suggested below. you have to decide what course of
action you want to take in these cases before we can really help you work
through the coding. - Cyanide_7
For text
>fields just check to see if the value == "";
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA