Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:04:07+00:00 2026-06-07T13:04:07+00:00

I want to create a drop down list that allows the user to choose

  • 0

I want to create a drop down list that allows the user to choose a Start and End “Year, Month, Day” as follows. When the page is updated, the choices are reverted to the “original” choices. How can I allow those selected values to save and remain when the page is updated?

<?php

if (isset($_POST['action']))
{
    $action = $_POST['action'];
    $startyear = $_POST['startyear'];
    $startmonth = $_POST['startmonth'];
    $startday = $_POST['startday'];
    $endyear = $_POST['endyear'];
    $endmonth = $_POST['endmonth'];
    $endday = $_POST['endday'];
}
else
{
    $action = "";
    if (!isset($_POST['startyear']) || !isset($_POST['startmonth']) || !isset($_POST['startday']) 
        || !isset($_POST['endyear']) || !isset($_POST['startmonth']) || !isset($_POST['startday']))
    {
        $startyear = "";
        $startmonth = "";
        $startday = "";
        $endyear = "";
        $endmonth = "";
        $endday = "";
    }
    else
    {
        $startyear = $_POST['startyear'];
        $startmonth = $_POST['startmonth'];
        $startday = $_POST['startday'];
        $endyear = $_POST['endyear'];
        $endmonth = $_POST['endmonth'];
        $endday = $_POST['endday'];
    }

}

if ($action == "update")
{
    echo "<h3>Start: $startyear-$startmonth-$startday | End: $endyear-$endmonth-$endday</h3>";
}

else
{
    if ($startyear == "" || $endyear == "")
    {
    // something belongs here...not sure
    }
    echo "<h3>Start: $startyear-$startmonth-$startday | End: $endyear-$endmonth-$endday</h3>";
?>

Selections for start/end year,month,day are here:

<form name='update' action='testing.php' method='POST'>
Start: <select name='startyear'>
    <option value="1">2012</option>
    <option value="2">2011</option>
    <option value="3">2010</option>
    <option value="4">2009</option>
    <option value="5">2008</option>
    <option value="6">2007</option>
    <option value="7">2006</option>
    <option value="8">2005</option>
    <option value="9">2004</option>
    <option value="10">2003</option>
    <option value="11'>2002</option>
    <option value="12">2001</option>
    <option value="13">2000</option>
    <option value="14">1999</option>
    <option value="15">1998</option>
</select>
<select name='startmonth'>
    <option value="1">01</option>
    <option value="2">02</option>
    <option value="3">03</option>
    <option value="4">04</option>
    <option value="5">05</option>
    <option value="6">06</option>
    <option value="7">07</option>
    <option value="8">08</option>
    <option value="9">09</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
</select>
    <select name='startday'>
    <option value="1">01</option>
    <option value="2">02</option>
    <option value="3">03</option>
    <option value="4">04</option>
    <option value="5">05</option>
    <option value="6">06</option>
    <option value="7">07</option>
    <option value="8">08</option>
    <option value="9">09</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
</select>
<br>
End:<select name ='endyear'>
    <option value="1">2012</option>
    <option value="2">2011</option>
    <option value="3">2010</option>
    <option value="4">2009</option>
    <option value="5">2008</option>
    <option value="6">2007</option>
    <option value="7">2006</option>
    <option value="8">2005</option>
    <option value="9">2004</option>
    <option value="10">2003</option>
    <option value="11'>2002</option>
    <option value="12">2001</option>
    <option value="13">2000</option>
    <option value="14">1999</option>
    <option value="15">1998</option>
</select>
<select name='endmonth'>
    <option value="1">01</option>
    <option value="2">02</option>
    <option value="3">03</option>
    <option value="4">04</option>
    <option value="5">05</option>
    <option value="6">06</option>
    <option value="7">07</option>
    <option value="8">08</option>
    <option value="9">09</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
</select>
    <select name='endday'>
    <option value="1">01</option>
    <option value="2">02</option>
    <option value="3">03</option>
    <option value="4">04</option>
    <option value="5">05</option>
    <option value="6">06</option>
    <option value="7">07</option>
    <option value="8">08</option>
    <option value="9">09</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
</select>
<input type='submit' value='Compare'/>
</form>
 <?php
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:04:09+00:00Added an answer on June 7, 2026 at 1:04 pm

    Instead of having such large HTML let php render it for you, this also allows you to determine if the selected attribute is rendered in the option.

    To keep the values selected in the form the form needs tobe posted back to the same php script its being rendered from action='', and a little logic is required on the posted values to check if the value equals itself, check the form below.

    <?php 
    //Build an array of values for your forms
    $year  = range(1998,2012);
    $month = range(01,12);
    $day   = range(01,31);
    
    //Handle POST, just an example
    if($_SERVER['REQUEST_METHOD']=='POST'){
        foreach($_POST as $key=>$value){
            if(is_numeric($value)){
                $$key = $value;
            }
        }
        /**
         * All POST keys like: startmonth ect will now be php variables like
         * $startmonth
         */
    
        //Do somthing with $startmonth ect
    }
    
    //A more tidy form
    ?>
    <form name='update' action='' method='POST'>
    Start: <select name='startyear'>
        <?php foreach(array_reverse($year) as $y):?>
        <option value="<?=$y?>"<?=((isset($startyear) && $startyear == $y)?' selected':null)?>><?=$y?></option>
        <?php endforeach;?>
    </select>
    <select name='startmonth'>
        <?php foreach($month as $m): $m = str_pad($m, 2, "0", STR_PAD_LEFT);?>
        <option value="<?=$m;?>"<?=((isset($startmonth) && $startmonth == $m)?' selected':null)?>><?=$m;?></option>
        <?php endforeach;?>
    </select>
        <select name='startday'>
        <?php foreach($day as $d): $d = str_pad($d, 2, "0", STR_PAD_LEFT);?>
        <option value="<?=$d;?>"<?=((isset($startday) && $startday == $d)?' selected':null)?>><?=$d;?></option>
        <?php endforeach;?>
    </select>
    <br>
    End: <select name='endyear'>
        <?php foreach(array_reverse($year) as $y):?>
        <option value="<?=$y?>"<?=((isset($endyear) && $endyear == $y)?' selected':null)?>><?=$y?></option>
        <?php endforeach;?>
    </select>
    <select name='endmonth'>
        <?php foreach($month as $m): $m = str_pad($m, 2, "0", STR_PAD_LEFT);?>
        <option value="<?=$m;?>"<?=((isset($endmonth) && $endmonth == $m)?' selected':null)?>><?=$m;?></option>
        <?php endforeach;?>
    </select>
        <select name='endday'>
        <?php foreach($day as $d): $d = str_pad($d, 2, "0", STR_PAD_LEFT);?>
        <option value="<?=$d;?>"<?=((isset($endday) && $endday == $d)?' selected':null)?>><?=$d;?></option>
        <?php endforeach;?>
    </select>
    <input type='submit' value='Compare'/>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a drop down list that allows the user to choose
Lets say that I have a drop down list that I want to create
I have a model called managers, I want to create a drop down list
I want to create a form for my user which shows a drop down
i m trying to create a drop down list that takes values on the
I want to create 5 text boxes created on drop down selected index change
I want create wordpress website into which I want create user management... That means
I am writing a UserControl that will act kinda like a drop down list,
I'm trying to create a default value for my dynamic drop down list. After
I am attempting to create a drop-down list populated with a range from another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.