• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Dynamic Dropdown for Credit Card Expiration Year

Dynamic Dropdown for Credit Card Expiration Year 4 years 10 months ago #40264

  • meschesm
  • meschesm's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Hi all,
I am posting a JavaScript code that Adrian in Support helped me with that populates a drop down with the current year and the following 14 years for a credit card expiration date field. Place this code in the FormProperties:CSS and Javascript:Javascript box. Change the field name in lines 3 and 9 to your field's name (e.g. 'expiration_year'). The dropdown values will now automatically be kept current.

I repurposed this code from another example and Adrian helped me get it working for my form. If there are any errors or omissions, or if there is a better way of doing this, it is my fault and in no way reflects on Adrian. Advice is always welcome!
<script type="text/javascript">
setTimeout(function(){
	document.getElementById('expiration_year').options.length = 0; // Set getElementByID to field name (e.g., expiration_year)
 
	year = new Date().getFullYear();
 
	min = year; // Set to current year
	max = year+14; // Set to current year + 14 years
	select = document.getElementById('expiration_year'); // Set getElementByID to field name (e.g., expiration_year)
 
	//insert placeholder "YYYY"
        opt = document.createElement('option');
		opt.value = "";
		opt.text = "YYYY";
                select.appendChild(opt);
       //insert current year + 14 years worth of values
        for (var i = min; i<=max; i++){
		opt = document.createElement('option');
		opt.value = i;
		opt.text = i;
		select.appendChild(opt);
	}
}, 1000);
</script>
 
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!