Populating Dates based on month and year selection

Populating Dates based on month and year selection
0.0 0


I have 3 dropdown selections for the user to input her birthday:

<select id= "birthYear"></select>
<select id="birthMonth"></select>
<select id= "birthDate"></select>

I want to populate the last selection (birthDate) with the right number of date options (28, 29, 30, 31) based on the selected year and month (in order to account for difference of days per month and per leap years).

Ive tried various versions of the following, but I NEED HELP AND INSIGHT, PLZ!:

function daysInMonth(m, y) {
  this.m = birthMonth.selectedIndex;
  this.y = birthYear.value;
  return new Date().getDate(y, m, 0);

function popDate() {
  for (i = 1; 1 < daysInMonth + 1; i++) {
    var opt = document.createElement('option');
    opt.value = i;
    opt.innerHTML = i;


I Googled “determine days in month javascript” and it led me to this: https://stackoverflow.com/questions/1184334/get-number-days-in-a-specified-month-using-javascript
Does that answer it for you?


Yes it does help! Turns out I had the arguments in the Date method instead of the actual Date object. Im still playing around with the formatting, but the tests all work. Thank you very much. ~WR


Awesome! You’re welcome and good luck!