• 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: Calculation with conditional fields

Calculation with conditional fields 12 years 4 months ago #20573

  • nvsdesign
  • nvsdesign's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 1
Hello,

I've set up a form with conditional fields and now I want to use them for calculation. The form does the following:

Select product A -> See prices of A
Select product B -> See prices of B

When a user selects price A in combination with an extra product C (radio buttons yes or no) the form calculates the total amount, using the script from the demo page. But now comes the problem:

When the user first selects product A and the price but later changes the product to B, the form calculates the total amount of both products. Instead of that the form only needs to select one price, no matter what choices I make. So it's only A + C or B + C, not A + B + C.

This is my script:
<script type="text/javascript">
function calculateList()
{
 
var op1=document.getElementById('Aantal_zv'); // This is field product A
var op2=document.getElementById('Aantal_mv'); // This is field product B
var op3=document.getElementsByName('form[Proefdruk]'); // This is field extra product
 
var result=document.getElementById('Totaal'); // This is the total amount
 
if(op1.value=="" || op1.value!=parseFloat(op1.value)) op1.value=0;
if(op2.value=="" || op2.value!=parseFloat(op2.value)) op2.value=0;
if(op3.value=="" || op3.value!=parseFloat(op3.value)) op3.value=0;
 
result.value=0;
 
result.value=parseInt(result.value);
 
for(i=0;i<op1.length;i++)
if(op1.options[i].selected) result.value=parseInt(result.value)+parseInt(op1[i].value);
 
for(i=0;i<op2.length;i++)
if(op2.options[i].selected) result.value=parseInt(result.value)+parseInt(op2[i].value);
 
for(i=0;i<op3.length;i++)
if(op3[i].checked) result.value=parseInt(result.value)+parseInt(op3[i].value);
 
}
</script>

You can see the live version of the form on www.actie-enveloppen.nl/nieuw. Scroll down and click one of the four buttons "bereken prijs".

I hope someone can help me!
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!