Dynamically populate Year in DropDownList
-
Hi,
I am using selectbox for academic year and want to add 2024 automatically when 2024 will start
I used this code and years from 1950 to 2023 loaded successfully but after form submission academic year field in user edit page( /wp-admin/user-edit.php ) were empty.
<script type="text/javascript"> window.onload = function () { //Reference the DropDownList. var ddlYears = document.getElementById("academic_year"); //Determine the Current Year. var currentYear = (new Date()).getFullYear(); //Loop and add the Year values to DropDownList. for (var i = 1950; i <= currentYear; i++) { var option = document.createElement("OPTION"); option.innerHTML = i; option.value = i; ddlYears.appendChild(option); } }; </script>
Could you please send me proper code snippet which will work with dropdown.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Dynamically populate Year in DropDownList’ is closed to new replies.