• 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: Multiple calculations, what is wrong in javascript

Multiple calculations, what is wrong in javascript 12 years 8 months ago #14758

  • lucvg
  • lucvg's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
What is wrong on the code below ? I used the code from the PayPal example, and that works fine...
But now I would have a simular calculation on a second page. Put I got only the calculation of 1 ex * price, and not the right calculation when I put more then 1 ex in the dropdown field.

Any idea what is wrong ?

<script type="text/javascript">
function enableQuantity(prod,quantity)
{
	if(document.getElementById(prod).checked)
		document.getElementById(quantity).disabled = false;
 
	else
		document.getElementById(quantity).disabled = true;
calculateTotal();		
 
}
 
function calculateTotal()
{
	var products = new Array("Product10","Product20","Product30");
	var i=0;
	var total = 0;
	for(i;i<products.length;i++)
		if(document.getElementById(products[i]).checked)
		{
 
			//alert(document.getElementById("QuantityProd"+(i+1)).value);
			total  = total + parseInt(document.getElementById(products[i]).value) * parseInt(document.getElementById('QuantityProd'+(i+1)).value);
		}
	document.getElementById('Total').value = total;
}
 
window.addEvent('domready', function() {
enableQuantity('Product10','QuantityProd1');
enableQuantity('Product20','QuantityProd2');
enableQuantity('Product30','QuantityProd3');
 
});
 
 
function enableQuantity1(prod1,quantity1)
{
	if(document.getElementById(prod1).checked)
		document.getElementById(quantity1).disabled = false;
 
	else
		document.getElementById(quantity1).disabled = true;
calculateTot1();		
 
}
 
function calculateTot1()
{
	var products1 = new Array("Product40","Product50");
	var x=0;
	var totala = 0;
	for(x;x<products1.length;x++)
		if(document.getElementById(products1[x]).checked)
		{
 
			//alert(document.getElementById("QuantityProd"+(x+1)).value);
			totala  = totala + parseInt(document.getElementById(products1[x]).value) * parseInt(document.getElementById('QuantityProd'+(x+1)).value);
		}
	document.getElementById('Total1').value = totala;
}
 
window.addEvent('domready', function() {
enableQuantity1('Product40','QuantityProd4');
enableQuantity1('Product50','QuantityProd5');
 
});
 
</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!