• 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: Checkbox Calculations

Checkbox Calculations 13 years 9 months ago #11198

  • didomi
  • didomi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Hi Forum,

The example code below works really well to total up the values of selected radio buttons but does anyone know how to achieve the same thing with checkboxes?

Essentially I have a few radio buttons that calculate the cost of a product but I need a checkbox at the end that can add an optional postage supplement.

Many Thanks,
Chris
function calculate() {
 
var val0=document.getElementsByName('form[style]');
var val1=document.getElementsByName('form[boardA]');
var result=document.getElementById('total');
 
result.value=0;
 
for(i=0;i<val0.length;i++)
if(val0[i].checked) result.value=parseFloat(result.value)+parseFloat(val0[i].value);
 
for(i=0;i<val1.length;i++)
if(val1[i].checked) result.value=parseFloat(result.value)+parseFloat(val1[i].value);
 
result.value=(parseFloat(result.value)).toFixed(2);
 
}
The administrator has disabled public write access.

Re:Checkbox Calculations 13 years 9 months ago #11207

  • didomi
  • didomi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Any thoughts on this? Even a simple, "no, this can't be done" would be great so I can look at other solutions.

Thanks all,
The administrator has disabled public write access.

Re:Checkbox Calculations 13 years 9 months ago #11209

  • didomi
  • didomi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Solved.

The syntax I was try to identify the checkbox with was...
var val10=document.getElementsById('express');

or
var val10=document.getElementsByName('form[express]');

but this is the one that worked...
var val10=document.getElementsByName('form[express][]');
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!