How To Remember Posted Fields In Forms For Drop Down Items?
I'm creating a simple registration page:
Solution 1:
At the top:
$birthdayMonth = $_POST['birthdayMonth']
In the select
:
<selectname="birthdayMonth"><optionvalue="-1">Month:</option><optionvalue="01"<?phpecho$birthdayMonth == '01' ? 'selected="selected"' : ''; ?>>Jan</option><optionvalue="02"<?phpecho$birthdayMonth == '02' ? 'selected="selected"' : ''; ?>>Feb</option><optionvalue="03"<?phpecho$birthdayMonth == '03' ? 'selected="selected"' : ''; ?>>Mar</option><optionvalue="04"<?phpecho$birthdayMonth == '04' ? 'selected="selected"' : ''; ?>>Apr</option><optionvalue="05"<?phpecho$birthdayMonth == '05' ? 'selected="selected"' : ''; ?>>May</option><optionvalue="06"<?phpecho$birthdayMonth == '06' ? 'selected="selected"' : ''; ?>>Jun</option><optionvalue="07"<?phpecho$birthdayMonth == '07' ? 'selected="selected"' : ''; ?>>Jul</option><optionvalue="08"<?phpecho$birthdayMonth == '08' ? 'selected="selected"' : ''; ?>>Aug</option><optionvalue="09"<?phpecho$birthdayMonth == '09' ? 'selected="selected"' : ''; ?>>Sep</option><optionvalue="10"<?phpecho$birthdayMonth == '10' ? 'selected="selected"' : ''; ?>>Oct</option><optionvalue="11"<?phpecho$birthdayMonth == '11' ? 'selected="selected"' : ''; ?>>Nov</option><optionvalue="12"<?phpecho$birthdayMonth == '12' ? 'selected="selected"' : ''; ?>>Dec</option></select>
Solution 2:
This is a really dirty of what doing what you want, but it will work:
http://www.plus2net.com/php_tutorial/pb-drop.php
It would be better to use loop to build the dropdown and then add the selected="selected" value to the correct option.
Solution 3:
<optionvalue="03"<?phpecho$_POST['birthdayMonth'] == '03' ?
'selected="selected"' : ''?>>Mar</option>
Post a Comment for "How To Remember Posted Fields In Forms For Drop Down Items?"