Mega Code Archive

 
Categories / Php / Form
 

Setting a default value in a select menu

<? $sweets = array('puff' => 'A',                  'square' => 'C',                  'cake' => 'B',                  'ricemeat' => 'S'); print '<select name="sweet">'; foreach ($sweets as $option => $label) {     print '<option value="' .$option .'"';     if ($option == $defaults['sweet']) {         print ' selected="selected"';     }     print "> $label</option>\n"; } print '</select>'; ?>