Repopulating Form Field
Posted: Thu Oct 18, 2007 8:42 am
I've got a form with a drop-down box. The box is within a loop that generates every number from 1 to 30 and then displays it in the box. When the form is submitted and there is a validation error of some sort, I want the drop-down box to be repopulated with the option the user selected.
For some reason though, when the form is reloaded, the value of the drop-down box just sets itself to the default value of "01".
Here's the code for the loop:
The variable $days is definetily working, begins the drop-down box lists 01-30. But it doesn't seem to be recognised in the IF statement. Anyone got any ideas what's going on?
Thanks.
For some reason though, when the form is reloaded, the value of the drop-down box just sets itself to the default value of "01".
Here's the code for the loop:
Code: Select all
<select name="day">
<? $i=1; while ($i<=30)
{?>
<? $days=sprintf('%02u', $i);?>
<option <? if(isset($form['day']) and $form['day']==$days) {?> selected="yes"<? }?> value="<?=$days;?>"><?=$days;?></option>
<? $i++;?>
<?
}?>
</select>Thanks.