keep selected item in Select after post
Posted: Sun Nov 21, 2010 6:16 am
hi all,
my first post here!!! learning to be a PHP programmer now!!!
I've made 3 date selection SELECT boxes displaying month/day/year but I'm not able to return the previously selected item after POST..
My code
I will have some validation on the date afterwards, for which I need to keep the selected items after sumbit so that user doesn't have to reselect his date if it fails validation... Pls hint me where & how "Selected" Tag will be inserted in these dynamically created drop down boxes..
Regards.
my first post here!!! learning to be a PHP programmer now!!!
I've made 3 date selection SELECT boxes displaying month/day/year but I'm not able to return the previously selected item after POST..
My code
Code: Select all
<?php
echo '
<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June','July', 'August', 'September', 'October', 'November', 'December');
$weekday = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
$days = range (1, 31);
$years = range (2005, 2015);
//**********************************************
echo "Month: <select name='month' id='month'>";
foreach ($months as $value) {
echo '<option value="'.$value.'">'.$value.'</option>\n';
} echo '</select><br />';
echo "Day: <select name='day' id='day'>";
foreach ($days as $value) {
echo '<option value="'.$value.'">'.$value.'</option>\n';
} echo '</select><br />';
echo "Year: <select name='year' id='year'>";
foreach ($years as $value) {
echo '<option value="'.$value.'">'.$value.'</option>\n';
}
echo '</select><input type="submit" /></form>';
echo $_POST['month']."/".$_POST['day']."/".$_POST['year'];
?>Regards.