in reply to Re: Dynamically marking a HTML select option as selected
in thread Dynamically marking a HTML select option as selected

I applaud you mentioning CGI.pm, it does have a solution - it's just not the radio_group method, it's popup_menu, or scrolling_list, depending on weather you want a single selection drop-down or a multi-value scrolling list box.
$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'}, );
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.

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