Hi! I have the following function that takes the fields and does calculations with them to get a total. The problem is that someone put in a word instead of a number and the program errored out. I would like to check for a number. If it is a number - do calculations, if not a number - put a zero in and do calculations.
THANKS~ Any help is greatly appreciated!
<!--FUNCTION TO CALCULATE THE TOTAL AMOUNT-->
<script language="javascript">
function calctotal()
{
lvShip = parseFloat(document.forms['ordersnewform'].elements['OrderShipping'].value-0);
lvShip = parseFloat(document.forms['ordersnewform'].elements['OrderShipping'].value-0);
lvMisc = parseFloat(document.forms['ordersnewform'].elements['OrderMisc'].value-0);
lvUnitPrice1 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice1'].value-0);
lvUnitPrice2 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice2'].value-0);
lvUnitPrice3 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice3'].value-0);
lvUnitPrice4 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice4'].value-0);
lvUnitPrice5 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice5'].value-0);
lvUnitPrice6 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice6'].value-0);
lvQuantity1 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity1'].value-0);
lvQuantity2 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity2'].value-0);
lvQuantity3 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity3'].value-0);
lvQuantity4 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity4'].value-0);
lvQuantity5 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity5'].value-0);
lvQuantity6 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity6'].value-0);
lvUnit1 = lvUnitPrice1 * lvQuantity1
lvUnit2 = lvUnitPrice2 * lvQuantity2
lvUnit3 = lvUnitPrice3 * lvQuantity3
lvUnit4 = lvUnitPrice4 * lvQuantity4
lvUnit5 = lvUnitPrice5 * lvQuantity5
lvUnit6 = lvUnitPrice6 * lvQuantity6
lvTotal = lvShip + lvMisc + lvUnit1 + lvUnit2 + lvUnit3 + lvUnit4 + lvUnit5 + lvUnit6;
document.forms['ordersnewform'].elements['OrderTotals'].value = lvTotal.toFixed(2);
return true;
}
</script>
THANKS~ Any help is greatly appreciated!
<!--FUNCTION TO CALCULATE THE TOTAL AMOUNT-->
<script language="javascript">
function calctotal()
{
lvShip = parseFloat(document.forms['ordersnewform'].elements['OrderShipping'].value-0);
lvShip = parseFloat(document.forms['ordersnewform'].elements['OrderShipping'].value-0);
lvMisc = parseFloat(document.forms['ordersnewform'].elements['OrderMisc'].value-0);
lvUnitPrice1 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice1'].value-0);
lvUnitPrice2 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice2'].value-0);
lvUnitPrice3 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice3'].value-0);
lvUnitPrice4 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice4'].value-0);
lvUnitPrice5 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice5'].value-0);
lvUnitPrice6 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice6'].value-0);
lvQuantity1 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity1'].value-0);
lvQuantity2 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity2'].value-0);
lvQuantity3 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity3'].value-0);
lvQuantity4 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity4'].value-0);
lvQuantity5 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity5'].value-0);
lvQuantity6 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity6'].value-0);
lvUnit1 = lvUnitPrice1 * lvQuantity1
lvUnit2 = lvUnitPrice2 * lvQuantity2
lvUnit3 = lvUnitPrice3 * lvQuantity3
lvUnit4 = lvUnitPrice4 * lvQuantity4
lvUnit5 = lvUnitPrice5 * lvQuantity5
lvUnit6 = lvUnitPrice6 * lvQuantity6
lvTotal = lvShip + lvMisc + lvUnit1 + lvUnit2 + lvUnit3 + lvUnit4 + lvUnit5 + lvUnit6;
document.forms['ordersnewform'].elements['OrderTotals'].value = lvTotal.toFixed(2);
return true;
}
</script>