Skip to navigation
Create a JavaScript year object for a select tag
11.08.20
function create_last_year(years=5) { let today = new Date().getFullYear(); from = today - years; let o = {}; for(let x=from;x <= today; x++) { if(x == today) { o[x] = {'key':x,'selected':true}; } else { o[x] = {'key':x}; } } return o; }
Reply
Anonymous
function create_last_year(years=5, select=false) { let today = new Date().getFullYear(); if(select === false) { select = today; } from = today - years; let o = {}; for(let x=from;x <= today; x++) { if(x == select) { o[x] = {'key':x,'selected':true}; } else { o[x] = {'key':x}; } } return o; }
11.08.20
Reply
Anonymous
Information Epoch 1732586345
Your system is just a path for moving data along.
Home
Notebook
Contact us