simonz has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks
I am creating a popup_menu each time I am fetching a new set of values from the database. But I am running into a problem as default values of popup_menus are retained across queries.
I am using a conditional statement as below, please help me with a way so that every time it is created the previous values are not maintained.
I think I am making some syntax error and have to mention it as an array ref but not sure how can I do that while using
a conditional statement
while(defined (my $row = $stmt->fetchrow_hashref)) { my $x = $row->{CONNECTION}; my $y = $row->{CARRY}; my $drop_down = $cgi->popup_menu( -name => "CHOICE", -values => [ 0 .. 6 ], -labels => { 0 => 'NO', 1 => 'A', 2 => 'B', 3=> 'C', 4 => 'D', 5 => 'E', 6 => 'F' }, -default => ($row->{CONNECTION} eq 'Y' && $row->{CARRY}) ? $row->{CARRY}: 0, );
When the above mechanism did not work, I tried the following one as well i.e taking the decision first in an if-else and then assigning the value but it did not work either :
while(defined (my $row = $stmt->fetchrow_hashref)) { my $x = $row->{CONNECTION}; my $y = $row->{CARRY}; my $default; if ($x eq 'Y') { if ($y) { $default = $y; } } my $drop_down = $cgi->popup_menu( -name => "CHOICE", -values => [ 0 .. 6 ], -labels => { 0 => 'NO', 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => 'E', 6 => 'F' }, -default => $default, );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: popup_menus retaining values across queries
by Anonymous Monk on Sep 01, 2014 at 12:21 UTC | |
by simonz (Sexton) on Sep 01, 2014 at 12:56 UTC | |
|
Re: popup_menus retaining values across queries ( CGI->new({}) -override => 1 )
by Anonymous Monk on Sep 01, 2014 at 21:18 UTC | |
by afoken (Chancellor) on Sep 03, 2014 at 17:25 UTC |