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 6680253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:27:12+00:00 2026-05-26T04:27:12+00:00

Ok so I was trying to have a form dropdown menu autoselect the current

  • 0

Ok so I was trying to have a form dropdown menu autoselect the current date without too much javascript coding, so I got the code below (it doesn’t autoselect, but it does include the current date as the first options). The year wasn’t showing up first like it was supposed to. I did the same for day and month, and those 2 worked perfectly, yet when I had the same code, except days / months in place of years (mday and mon inside brackets), the first year selection wasn’t appearing. I’m guessing the problem is the part inside two instances of [$t[‘year’]]. The rest of the code is functioning fine, but I just included it in case I missed something about it (I also tried replacing all years with the last their respective last 2 digits but same result).

<?php
$t = getdate(time()); 
$year = array(1 =>'2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023', '2024', '2025', '2026', '2027', '2028', '2029', '2030'); 

echo '&nbsp Year <select name="year" >'; 
echo '<option value="\" . $t[\'year\'] . \"">' . $year[$t['year']] . '</option>'; 
foreach( $year as $key => $value ) { 
    echo "<option value = \"$key\">$value</option>"; 
} 
echo '</select>'; ?>
  • 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-05-26T04:27:12+00:00Added an answer on May 26, 2026 at 4:27 am

    Use date('Y').

    http://php.net/manual/en/function.date.php

    <?php
    $t = getdate(time()); 
    $year = array('2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023', '2024', '2025', '2026', '2027', '2028', '2029', '2030'); 
    
    echo '&nbsp Year <select name="year" >'."\n"; 
    echo '<option value="' . array_search(date('Y'),$year) . '">' . date('Y') . '</option>'."\n"; 
    foreach( $year as $key => $value ) { 
        echo "<option value = \"$key\">$value</option>\n"; 
    } 
    echo '</select>'."\n";
    
    ?>
    

    http://codepad.org/7h2MnxzC

    This will also select just the one value in the select, so you don’t need two:

    <?php
    $t = getdate(time()); 
    $year = array('2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023', '2024', '2025', '2026', '2027', '2028', '2029', '2030'); 
    $c_year = date('Y');
    
    echo '&nbsp Year <select name="year" >'."\n"; 
    foreach( $year as $key => $value ) { 
        echo "<option".($c_year == $value?' selected="true"':'')." value = \"$key\">$value</option>\n"; 
    } 
    echo '</select>'."\n";
    
    ?>
    

    http://codepad.org/uGx6zoyn

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert from code behind on an asp.net form, I have
first of all I'm trying to have the dropdown menu send input value to
I have a form that is trying to insert some data into an SQL
I have a form within an ASP.NET MVC application and I'm trying to submit
I'm trying to have the action of a HTML form built when the user
I have a WPF form where I'm trying to make a simple input form.
Please have a look at this form that I am trying to design with
I have run into a problem trying to modify a form I myself have
i have a label in my form, and im trying to get the value
I have a View with an exposed form . I am trying to a

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.