Posted by Richard Levasseur on 03/10/06 21:04
Best practice would be to use a class that encapsulates all of this,
where the basic logic would be, more or less, in a simple model:
Have a value that keeps the track of the selected item, an array of all
the items, and a loop that checks if the currently outputted value is
selected or not.
in almost-correct-code:
$options = array();
$options['msword'] = 'MS Word';
$options['txt'] = 'Text File';
$selectedKey = null;
echo "<selct bla bla>";
foreach($options as $key=>$value) {
$selected = '';
if($key == $selectedKey)
$selected = 'selected';
}
echo "<option name='foo' value='$key' $selected>$value</option>"
}
echo "</select>"
You can use the same procedure for radio buttons.
[Back to original message]
|