B2B Marketing Insights by Ironpaper

Automatically extend years in static dropdown checkout forms using javascript

Written by Ironpaper | October 28, 2011

There are many ecommerce websites that have static coded checkout forms. For these forms, the code to populate the drop down lists for years may be hard coded, which presents longterm problems for your website. In cases where PHP or another suitable language is prohibited, you may be looking for a way to expand the year option of a field automatically.  If so, you can insert this javascript in in place of the hard coded <option>s, it will set the years options to be the current and go up to 10 in the future.

This solution works great with Adobe Business Catalyst projects, where the original eCommerce form has been manually over-written (for whatever reason).

<script type="text/javascript">

var d = new Date();
var curyr =d.getFullYear();
document.write('<option selected="true" value="'+curyr+'">'+curyr+'</option>');
for(cur=curyr;cur<curyr+11;cur++){
document.write('<option value="'+cur+'">'+cur+'</option>');
}

</script>