modcar Posted July 13, 2010 Share Posted July 13, 2010 Evening; I am creating a 5 part registration form, with sets of fields dynamically created, depending on the options a user has previously selected. Step 4 is where I'm having issues, I cannot get the form calculator working. I have tried having the javascript in the loop, and out, but no difference. code for calculator: <script type="text/javascript"> function startCalc2(){ interval = setInterval("calc2()",1); } function calc2(){ one_lic_total = document.autoSumForm.car1_lic_quote.value; two_lic_total = document.autoSumForm.car2_lic_quote.value; document.autoSumForm.reg_quote.value = ((one_lic_total * 1) + (two_lic_total * 1)).toFixed(2); total_lic = document.autoSumForm.lic_quote.value; total_admin = document.autoSumForm.admin_fee_quoted1.value; document.autoSumForm.quote_total.value = ((total_lic * 1) + (total_admin * 1)).toFixed(2); calc_car1_lic = document.autoSumForm.car1_lic_12_6.value; document.autoSumForm.car1_lic_quote.value = (calc_car1_lic * 1) calc_car2_lic = document.autoSumForm.car2_lic_12_6.value; document.autoSumForm.car2_lic_quote.value = (calc_car2_lic * 1) } function stopCalc2(){ clearInterval(interval); } </script> This worked when there was only 1 or 2 cars, but, now that there could be any number of cars The feilds still follow the same naming as above, <select name="car<? echo $num; ?>_lic_12_6" id="car<? echo $num; ?>_lic_12_6" onChange="startCalc2()"> Link to comment https://forums.phpfreaks.com/topic/207566-javascript-calculator-in-php-loop/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.