Forums

Checkboxes group - looks simple, but...

CrystalFrontier 15 Apr, 2014
Dear forum,

I'd like to create a JS script that enables a registrant to select a value through a drop-down ('fees') and then tick an optional number of checkboxes ('days'). The value of the dropdown should multiply by the number of checked boxes ('days') and show in the sum total textbox ('total'), in the given example €12 * x number of days = 12/24/36...

Is this in any way possible with a few lines of JS or will it turn complicated because there is essentially no way to tell how many boxes are ticked just by working with mere values?

Any help would be much appreciated.

Thanks!
Chris

Max_admin 16 Apr, 2014
The code below should calculate the total based on the selection and the number of checkboxes checked, but you need to do few updates.

You also must either have v5 OR have JQuery loaded in the page if you have v4:


jQuery(document).ready(function($){
	var $days = 0;
	$('.checkboxes_class').on('click', function(){
		if(($this).prop('checked')){
			$days = $days + 1;
		}else{
			$days = $days - 1;
		}
	});
	//print the total
	$('#total_panel_id').text(parseInt($('#dropdown_id').val()) * $days);
});


Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.