|
Posted by rlee0001 on 03/10/06 20:42
Barry,
For a combo box (drop-down select), use something like this:
<label for='fld_location' accesskey='L'><u>L</u>ocations:</label>
<select id='fld_location' name='location[]'>
<?php
// POPULATE LOCATIONS
$locations = pg_query($db_conn, 'SELECT name FROM locations ORDER BY
name;');
if ($locations) {
while ($location = pg_fetch_object($locations)) {
echo '<option
value=\''.$location->name.'\''.(($location->name==$thisrecord->location)?'
selected=\'selected\'':'').'>'.$location->name.'</option>';
}
}
?>
</select>
The ternary operator (cond?val1:val2) is used to check each option. If
the option is the one currently selected output selected='selected',
otherwise output an empty string. If you have a static list (as opposed
to a database query), just put the ternary operator in each of the
options checking each options value against the current selection.
So the same thing in radio buttons using the ternary operator except
use checked='checked'. Hope that helped.
-Robert
Navigation:
[Reply to this message]
|