Simple calendar problem

Hi,
I tried creating the simple calendar and below is the code link

The problem i am facing is only if you select a month from the dropdown, the number of days would be displayed. I want January to be default just like how it is in this page (https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/conditionals);

I don’t want to manually add 31 li’s in my HTML.

Please let me know how can this be achieved?

Here’s the code link

https://codepen.io/harshitbadolla/pen/eYJaBJX

@Harshit_Badolla so, to get this clear, this code works fine, but the problem you’ve got is that you want it to display “January” and 31 days by default when it first loads, but it doesn’t display anything?

The problem is that you are only able to update the Month name and shown days when the change event fires, as all the code is inside the change handler. You should extract the part of the code that displays the month name and days out to a separate function, call that form inside the change handler, and then also call it separately when the page first loads, to show January by default.

1 Like

Thank you so much…I have updated the code and it works.
I have also updated the code in the above codepen link.

Thanks a lot.

Perfect, that is really nice work!