Jump to content

javascript calculator in php loop


modcar

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.