pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/mdn/dom-examples/pull/372

60.css" /> Initialize year selection to current year by dipikabh · Pull Request #372 · mdn/dom-examples · GitHub
Skip to content

Comments

Initialize year selection to current year#372

Open
dipikabh wants to merge 5 commits intomainfrom
fix-initialization
Open

Initialize year selection to current year#372
dipikabh wants to merge 5 commits intomainfrom
fix-initialization

Conversation

@dipikabh
Copy link
Contributor

@dipikabh dipikabh commented Jan 8, 2026

This is a follow up to #371, which was loading 2030 as the starting year in the form, picking from the first option in the HTML drop-down list.

This PR:

  • Sets the year on form load to the current year as well as after a to-do entry.
  • Updates the list of years in the drop-down to an ascending order.

Motivation

To avoid future updates to this UI every time the year changes

Additional details

The app link can be accessed at https://mdn.github.io/dom-examples/to-do-notifications/

@dipikabh dipikabh requested a review from a team as a code owner January 8, 2026 16:54
@dipikabh dipikabh requested a review from pepelsbey January 8, 2026 16:54
year.value = 2026;
day.value = "01";
month.value = "January";
year.value = new Date().getFullYear();
Copy link
Contributor Author

@dipikabh dipikabh Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this line (instead of hard-coding it to a year)

Comment on lines 91 to 103
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option>
<option value="2026">2026</option>
<option value="2027">2027</option>
<option value="2028">2028</option>
<option value="2029">2029</option>
<option value="2030">2030</option>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reordered this list to be in ascending order

Copy link
Member

@pepelsbey pepelsbey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you 😊

I have another idea: we can avoid changing the dates altogether, even in 2030!

This will generate a list of 13 options, starting with the current year (2026–2038)

  // Populate year options: current year and 12 years into the future
  const currentYear = new Date().getFullYear();
  for (let i = 0; i <= 12; i++) {
    const option = document.createElement("option");
    const yearValue = currentYear + i;
    option.value = yearValue;
    option.textContent = yearValue;
    year.appendChild(option);
  }

And then we set it:

  year.value = currentYear;

I would remove all the pre-filled years from HTML too and leave the <select> empty.

I wish I could’ve suggested it, but GitHub won’t allow it 🥲

image

@dipikabh
Copy link
Contributor Author

Sorry it took me a while to get back to this task.
Thanks for the review and nice suggestion! I've made the suggested updates.

I've added 2 more files to this PR:

  • to-do-notifications/README.md: Updated the description and added a link to the corresponding page in content
  • Repo README.md: An entry for this app was missing

I'll open a content PR to make sure the tutorial there reflects the same code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy