This topic is locked

Calculate on-the-fly

9/22/2010 11:01:06 AM
PHPRunner General questions
M
marthins author

Hi,
want to create an order and this order should have some itens. I created a table order and order_details using master_details relationship, so I add an order and then add details (itens) one by one. But I want to display unit price, total price (as the price may vary) and change values when the user changes the product selected.
I am using javascript onload events but I can not calculate total price when checking product by its name:
function compare() {

if (parseFloat(ctrlProd.getValue()) == 'Produto') {

ctrlTotal.setValue(parseFloat(ctrlPrice.getValue()));

} else{

ctrlTotal.setValue(parseFloat(ctrlPrice.getValue()) + parseFloat(ctrlPrice.getValue())((parseFloat(ctrlQuantity.getValue()))-1)0.6);

}

}
I dont know why this code doesnt work.
Regards
Anselmo

A
ann 9/23/2010

Anselmo,
try the following code:

function compare() {

if (ctrlProd.getValue() == 'Produto') {

ctrlTotal.setValue(parseFloat(ctrlPrice.getValue()));

}

else{

ctrlTotal.setValue(parseFloat(ctrlPrice.getValue()) + parseFloat(ctrlPrice.getValue())*((parseFloat(ctrlQuantity.getValue()))-1)*0.6);

}

}



If it doesn't help please publish the whole code of the JavaScript Onload Event (where you create ctrlTotal,ctrlPrice, etc controls and call compare() function).