I am trying to create a dynamic dropdown that will take the current year and iterate another 15 years to it so I don’t have to continue to update the credit card year dropdown field. I have successfully built the for loop but cannot seem to figure out how to put this inside a select tag.
You really had the right idea, you just really don’t want to use document.write() in that case. I’ve written up two methods above — one with vanilla JS, and one using jQuery.
First, you need to set a default option in your select in the HTML (I also cleaned that up and added a label, because I’m picky like that).
Then, with jQuery, it’s super easy — you just append additional option tags with your variable filling in the value. Same with plain-jane JS, except you have to use document.getElementById() and .insertAdjacentHTML().
Hence, this may be better done with PHP or similar. Just something to consider.