Welcome to The Perfect Curve.

The Eternal Problem of date pickers and calendar controls - the year

simon gray 2023-04-03, 19:09:30
Read this article aloud — 197 words

A friend earlier today shared this amusing image on Facebook:

A man on his computer entering his year of birth via a scrolling calendar picker; his son on the phone saying 'I can't use the computer today, my dad is scrolling down to his birth year'

 

This is a common problem with date calendar pickers on apps and websites - we want to make it easy for users to enter dates by a calendar, but if the date needing to be entered is more than a couple of years in the past it's a complete nightmare to scroll back.

If only there was a solution which could make this easier for users?


    <script>
function updateYear(year)
{
theYear = year + "-01-01";
document.getElementById('theDate').value=theYear
}
</script>
<label for="theYear">Year:</label><input type="number" id="theYear" name="theYear" onblur="updateYear(this.value)" /><br />
<label for="theDate">Date:</label><input type="date" id="theDate" name="theDate" />

Feel free to use, adapt, and share yourself!


    <script>
function updateYear(year)
{
theYear = year + "-01-01";
document.getElementById('theDate').value=theYear
}
</script>
<label for="theYear">Year:</label><input type="number" id="theYear" name="theYear" onblur="updateYear(this.value)" /><br />
<label for="theDate">Date:</label><input type="date" id="theDate" name="theDate" />

Feel free to use, adapt, and share yourself!

";

Brought to you by simon gray. Also find me on Mastodon

The code behind this site is a bit of an abandoned project; I originally had lofty ambitions of it being the start of a competitor for Twitter and Facebook, allowing other people to also use it turning it into a bit of a social network. Needless to say I got so far with it and thought who did I think I was! Bits of it don't work as well as I'd like it to work - at some point I'm going to return to it and do a complete rebuild according to modern standards.