Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

Dynamic Select Year List Script HTML Form Elements

Learn to program dynamic year select lists in HTML forms to avoid the need to write up to 100 lines in your HTML. The JavaScript loop will write the options for you in a for loop. We can do this easily because years are numeric and incremental. Adding the final year dynamically allows you to die as the programmer but still appear as if you are still updating your form every year. <!DOCTYPE html> <html> <body> <select id="year" name="year"> <script> var myDate = new Date(); var year = myDate.getFullYear(); for(var i = 1900; i < year+1; i++){ document.write('<option value="'+i+'">'+i+'</option>'); } </script> </select> </body> </html>
thumb

JavaScript Videos

Form Programming

Contact Form Web Application Tutorial Ajax HTML5 PHPCheckbox Toggle Tutorial Select Deselect All ElementsIn Place Editing CMS Development HTML JavaScript TutorialCustom Progress Bar Meter Development For File Upload FormsMultiphase Form Programming Tutorial Multi StepRestrict Text Input Characters HTML JavaScript TutorialMonthly Payment Loan Calculator Form Programming TutorialDynamic Select Year List Script HTML Form ElementsTip Calculator Application Form Programming Tutorialtextarea Form Field Character Counting and LimitingBuilding a WYSIWYG Rich Text Editor Textarea Replacement Part 1Building a WYSIWYG Rich Text Editor Textarea Replacement Part 2Div contenteditable Click Select All Text execCommand selectAllToggle Password Security Form Input Characters TutorialTrap User Check for Unsaved Written Work TutorialReal Time Text Input or Textarea Filter TutorialForm Select Change Dynamic List Option Elements Tutorial