Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: zero vs. empty

by screamingeagle (Curate)
on Mar 03, 2002 at 21:40 UTC ( #149018=note: print w/replies, xml ) Need Help??

in reply to zero vs. empty

you could check if the value returned from CGI->param('fieldname') is empty by using the length function
if length($cgi->param('fieldname')) == 0 (that means the field is empt +y.)
To check if the value is 0, how about :
if ($CGI->param('fieldname') == 0)...
Option 2: if u want to use Javascript, then this might work:
<html <head> <script language="Javascript"> function chkinput(objForm) { if (objForm.inputfield.value == "") { objForm.fld_has_value_or_not.value = "N" } else { objForm.fld_has_value_or_not.value = "Y" } objForm.submit(); return true; } </script> </head> <body> <form name="testfrm" method="post" action="cgifile.cgi" onSubmit="retu +rn chkinput(this);"> <input type=hidden name=fld_has_value_or_not value=""> <input type="text" name="inputfield" value=""> <input type=submit value="Submit"> </form> </body> </html>
in this case, if the input field is empty, the hidden variable will be set to "Y", which can be checked by the cgi file and processed accordingly...

Replies are listed 'Best First'.
Re: Re: zero vs. empty
by Juerd (Abbot) on Mar 03, 2002 at 23:06 UTC

    To check if the value is 0, how about :   if ($CGI->param('fieldname') == 0)...

    Keep in mind that "three" == 0. To check if the entered value equals the single character 0, use a string comparison: $something eq '0'.
    It's generally a good idea to warn if the user didn't enter nothing or digits. Or, using reversed logic: warn if a non-digit character is found:

    die "\$foo contains a non-digit character!\n" if $foo =~ /\D/;

    ++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
    Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
    -- vs lbh hfrq OFQ pnrfne ;)
        - Whreq

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://149018]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2018-06-25 10:58 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.