in reply to Re: Dynamically marking a HTML select option as selected
in thread Dynamically marking a HTML select option as selected
The other absolutely wonderful thing about CGI.pm is that if the parameter already has a value in the $query object (which you can set explicitly), it will automaticly have it's old value (i.e. it will stick) when you use $query to produce the html (that is if you don't set it explicitly as above). This is great for situations when you have to re-display an HTML page with a form to the user so they can either correct fields, or fill in required fields.$html .= $query->scrolling_list( -name => 'my_parameter', -values => [qw/option1 option2/], -default => $existing_value, -labels => { option1 => 'Option 1', option2 => 'Option 2'}, -multiple => 'true', ); # or $html .= $query->popup_menu( -name => 'my_parameter', -values => [qw/option1 option2/], -default => $existing_value, -labels => { option1 => 'Option 1', option2 => 'Option 2'}, );
If you want to have a default value without overwriting the user's entry, an easy thing to do is:
$query->param('my_parameter',$defaultValue) unless defined $query->p +aram('my_parameter');
hth
|
|---|