Jump to content

[SOLVED] Handling <select>, anything besides PEAR?


Gath

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/60459-solved-handling-anything-besides-pear/
Share on other sites

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>";
><

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.