I’ve read many tutorials on this subject and concluded with the below code. The problem is, the Selection box state value is not maintained when my validation fails.
I have two files:
application.php – this file processes the request.
and
form.php – which is where my select code is:
<select name="textfield6" id="textfield6" class="textbox" style="width:80px;">
<?
$states = array('AL' => "Alabama",
'AK' => "Alaska",
'AZ' => "Arizona",
'AR' => "Arkansas",
'CA' => "California",
...
'WA' => "Washington",
'WV' => "West Virginia",
'WI' => "Wisconsin",
'WY' => "Wyoming");
foreach ($states as $abr => $full) {
$selected = ($textfield6 == $abr) ? " select=\"selected\"" : "";
echo "<option value=\"$abr\"$selected>$full</option>\n";
}
?>
</select>
in the
$selectedvariable, it has to beselected="selected"instead ofselect="selected". (plus the escaping backslashes, of course!)