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?
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.
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:
Days:
Hope that helps.