By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

Adding an amount to an integer......

P: 47
i'll try and explain this as best i can.

i have a form with 3 radio buttons.

they have 3 values, 0, 5 and 10.

when the checkbox is checked, it adds that ammount to the total figure, currently 0.

i can't get it to work, maybe one of you guys could have a look at the code and tell where i'm going wrong, thanks.

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript1.2">
  2.  
  3. function calculateTotal()
  4.  
  5. {
  6.     var price,i;
  7.  
  8. for (i=0; i<document.formTotal.shipping.length;i++)
  9.     {
  10.         if (document.formTotal.shipping.checked=true)
  11.         {
  12.             parseInt (document.formTotal.total + 5);
  13.         }
  14.     }    
  15.  
  16. </script>
  17.  
  18.  



and the html.

Expand|Select|Wrap|Line Numbers
  1. <form name="formTotal" method="post" action="">
  2.  
  3.     <table width="100%" border="0" cellspacing="1" cellpadding="6">
  4.       <tr>
  5.         <td colspan="3" bgcolor="#FFF7D2"><span class="style3">Please choose your region for shipping </span></td>
  6.         </tr>
  7.       <tr>
  8.         <td align="center"><span class="style1"><strong>Ireland<br />
  9.         </strong>free </span><br />
  10.           <input name="shipping" type="radio" /></td>
  11.         <td align="center"><span class="style1"><strong>Other EU</strong><br />
  12.           &euro;5<br />
  13. </span>
  14.           <input name="shipping" type="radio" value="5" /></td>
  15.         <td align="center">&nbsp; <span class="style1"><strong>Rest of World</strong><br />
  16.           &euro;10<br />
  17. </span>
  18.           <input name="shipping" type="radio" value="10" /></td>
  19.       </tr>
  20.     </table>
  21. </form>
  22.       <table width="100%" border="0" cellspacing="1" cellpadding="6">
  23.         <tr>
  24.           <td colspan="2" bgcolor="#FFF7D2"><span class="style3">Shopping Cart </span></td>
  25.         </tr>
  26.         <tr>
  27.           <td><span class="style1">Quantity</span></td>
  28.           <td><span class="style1" id="quantity">0</span></td>
  29.         </tr>
  30.         <tr>
  31.           <td><span class="style1">Total</span></td>
  32.           <td><span class="style1" id="total">0</span></td>
  33.         </tr>
  34.       </table> 
  35.  
Oct 26 '07 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,390
hi ...

use:

Expand|Select|Wrap|Line Numbers
  1. parseInt(document.formTotal.total) + 5;
  2.  
kind regards
Oct 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.