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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:30:46+00:00 2026-05-21T21:30:46+00:00

I have 3 html <select> the year, month, and day. Both the year and

  • 0

I have 3 html <select> the year, month, and day. Both the year and month automatically sets to the current year and current month. I did that purely in PHP. However, the day which is being triggered by Javascript doesn’t seem to work even though I already did

if (j == <?php echo date('d') ?>)  days_select.options[days_select.options.length] = new Option(j, j, true);

The default day is still 1 not the current day. What is even frustrating is that when I checked it on firebug the selected day is the current day… I am a total noob in programming that’s why simple things like these are kinda hard for me to grasp. Pls help…

date_select.php

<body onload="loadDays();">
 <script type="text/javascript" >

  function loadDays() {
   var year = parseInt(document.getElementById('years').value);
   var month = document.getElementById('months').value;
   var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
   var days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

   if ((year % 4) == 0)  days[1] = 29;

   var days_select = document.getElementById('days');
   days_select.options.length = 0;

   for(i in months) {
    if (month == months[i]) {

     for(var j = 1; j <= days[i]; j++ ) {
      if (j == <?php echo date('d') ?>)  days_select.options[days_select.options.length] = new Option(j, j, true);
      else days_select.options[days_select.options.length] = new Option(j, j);
     }
     break;
    }
   }
  }

 </script>

 <span style="display: table; ">
  <span style="display: table-cell; ">
   <select id="years" onchange="loadDays();">
    <?php 
     for($year = 1900; $year <= 2100; $year++ ) {
      if ($year == date('Y')) echo "<option value='$year' selected=''>" . $year . "</option>";
      else echo "<option value='$year'>" . $year . "</option>";
     }
    ?>
   </select>
  </span>
  &nbsp;
  <span style="display: table-cell; ">
   <select id="months" onchange="loadDays();">
    <?php 
     $months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" );

     foreach($months as $month){
      if ($month == date('M')) echo "<option value='$month' selected=''> " . $month . "</option>";
      else echo "<option value='$month'> " . $month . "</option>";
     }
    ?>
   </select>
  </span>
  &nbsp;
  <span style="display: table-cell; ">
   <select id="days" >

   </select>
  </span>
 </span>
</body>
  • 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-21T21:30:47+00:00Added an answer on May 21, 2026 at 9:30 pm

    I’m putting this in as a separate answer since it, well, is one.

    The third parameter to Option() is whether the option is selected by default, as though it were specified in HTML. The fourth is whether it is actually selected right now. Add another true to your Option() call and it works for me in testing.

    new Option(j, j, true, true)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some php code that is creating an html table. Within it I
I have a list as such : <ul id=yearMenu> <li>Select a year</li> <li><a href=AJAX/2010PR.html>2010</a>
i have a html select with options in my views . onchange i want
I have a html select list menu,when user select an option he/she is redirected
OK, I have two HTML select elements and a button. I need to disable
I have a html combo/select. When the user selects a element, I want to
I have a html element (like select box input field) in a table. Now
I have a html form which have a select list box from which you
I have this HTML: <select multiple='multiple' size='3'> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> Using
I have this HTML dropdown: <form> <input type=text id=realtxt onkeyup=searchSel()> <select id=select name=basic-combo size=1>

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.