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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:35:31+00:00 2026-05-15T11:35:31+00:00

I have a javascript array of dates, in the form {year:’2010′,month:’6′,day:’23’} I need to

  • 0

I have a javascript array of dates, in the form

{year:'2010',month:'6',day:'23'}

I need to have three <select>s in a row, the first populated with the years in the list, the second populated with the months in the year selected by the first, and the third populated with the days corresponding to the selected year and month.

I do not have access to libraries like jQuery.

What is the best way to handle this?

  • 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-15T11:35:33+00:00Added an answer on May 15, 2026 at 11:35 am

    To retrieve the year data to setup the initial select, you’ll have to traverse the array at least once (hopefully only once).

    Due to the fact you want the second select populated in response to the first and the third populated based on the second and first, you’ll need a fast way to reference them.

    I’d initially populate the select, whilst sorting out the data into an easier to retrieve system. I’m using Arrays with keys here, others may suggest it is better to use Objects with keys instead.

    /* Global variables */
    var arr = new Array({year:'2010',month:'6',day:'23'},
                        {year:'2011',month:'6',day:'23'},
                        {year:'2010',month:'5',day:'23'});
    var srt = new Array();
    
    function populateArrs()
    {
    for(var i=0;i<arr.length;i++)
    {
      var y = arr[i].year;
      var m = arr[i].month;
      var d = arr[i].day;
      var in_select = false;
    
      /* Month array, day array */
      var mArr;
      var dArr;
    
      if(srt[y] != null)
      {
        mArr = srt[y];
        in_select = true;
      }
      else
        mArr = new Array();
    
    
      if(mArr[m] != null)
        dArr = mArr[m];
      else
        dArr = new Array();
    
      if(dArr[d] == null)
        dArr[d] = d;
      /* No else as at this stage it will already exist in array set */
    
      mArr[m] = dArr;
      srt[y] = mArr;
    
      /* Don't duplicate values in the select */
      if(!in_select) 
      {
        var opt = document.createElement('option');
        opt.value = y;
        opt.text = y;
        /* Get your year select */
        var ySel = document.getElementById('year_select'); 
        ySel.appendChild(opt);
      }
    }
    }
    
    if (window.addEventListener)
      window.addEventListener("load", populateArrs, false);
    else if (window.attachEvent)
      window.attachEvent("onload", populateArrs);
    

    Afterwards, you need to set up onclick events to populate your other selects dynamically. You can simply reference the appropriate arrays by using lookups and for..in loops.

    Months:

    var ySel = document.getElementById('year_select');
    var mArr = srt[ySel.options[ySel.selectedIndex].value];
    for( x IN mArr)
      /* Populate month select */
    

    Days:

    /*As above, then */
    var mSel = document.getElementById('month_select');
    var dArr = srt[mSel.options[mSel.selectedIndex].value];
    

    Hope that helps.

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

Sidebar

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.