Gath Posted July 17, 2007 Share Posted July 17, 2007 Hi. The problem is that i have a form that includes a birthdate in a <select> of Years, from 1900 up to 2000. What i need is when the form isnt properly filled, and returns to itself, for the select to be on the year that was chosen, if any, instead of returning to the default value. Checked the pear for it, but... too complicated for me Looked around for regex or something, but i'm not finding anything. (altought i'm so tired i might just missed it completly -.-). Any tips, ideas, or something? Thanks. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 17, 2007 Share Posted July 17, 2007 what ? what is regex ? why do you neeeeeed that you have a select menu right so the data are all coming on your format? Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 17, 2007 Share Posted July 17, 2007 Assuming your form uses the POST action ... something like this: <?php echo "<select name='the_year'>\n"; for ($i=1900;$i<2000;$i++) { echo "<option value='. $i. '"; if ($i == $_POST['the_year']) { echo " selected='selected'";} echo ">". $i. "</option>\n"; } echo "</select>"; >< Quote Link to comment Share on other sites More sharing options...
Gath Posted July 18, 2007 Author Share Posted July 18, 2007 Assuming your form uses the POST action ... something like this: <?php echo "<select name='the_year'>\n"; for ($i=1900;$i<2000;$i++) { echo "<option value='. $i. '"; if ($i == $_POST['the_year']) { echo " selected='selected'";} echo ">". $i. "</option>\n"; } echo "</select>"; >< Yeah, well, i said i was tired -.- anyway, that wasnt exactaly the my problem... it was a Country list. I dont even know why i typed the Year thingie... But thanks for your help. Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 18, 2007 Share Posted July 18, 2007 Same basic approach for anything. Assuming you have your country list in an array (who doesn't?) you iterate through the elements checking for equality at which point you echo out the selected = 'selected' bit ... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.