tbone has asked for the wisdom of the Perl Monks concerning the following question:

Using the cgi object for creating a popup_menu, for some reason I can not use 0 as a value. Instead of my value showing up as 0 its blank. Maybe I'm doing something wrong, but when I sub. anything elese for 0 I get a value when submited. Here is my code. Thanks
$q->radio_group(-name => "complete", -values => ["1","0","-1"], -labels => {1=>"Yes", 0=>"No", -1=>"N/A"}, -default =>" ")

Replies are listed 'Best First'.
Re: cgi popup_menu cant take 0
by arthas (Hermit) on Aug 22, 2003 at 15:38 UTC

    Hi!

    I tried your code, and it outputs the correct HTML:

    <input type="radio" name="complete" value="1" />Yes <input type="radio" name="complete" value="0" />No <input type="radio" name="complete" value="-1" />N/A
    I splitted the output in 3 lines for readability. There 0 is there, does it show this way to you? If it does, the problem probably lies elsewhere, i.e. where you process the submitted form.

    Michele.

Re: cgi popup_menu cant take 0
by tcf22 (Priest) on Aug 22, 2003 at 15:35 UTC
    This is generating the code fine. I get
    <input type="radio" name="complete" value="1" />Yes <input type="radio" name="complete" value="0" />No <input type="radio" name="complete" value="-1" />N/A
    which looks correct.

    My guess is that the problem lies in the script that recieves the data. Do you by any chance have something like this in that script: if($q->param('complete')) because in that case it will return 0 and not enter the if. If this is that case try using if(defined $q->param('complete'))
      Thanks guys...I'm an idiot. tcf22, I did exactly what you said with regards to the if statement. Thanks again.