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

Need Help with Calculator Java Script

P: n/a
So I am trying to get this Calculator to work. It needs to take in a
vaule, and select a shipping
Everythin works great except the shipping part. I need it to take the
shipping value and add it to the "Downpayment" and also the "Total
amount paid"
Example: item cost $20.00 , $8.50 shipped selected,
Payment 1 = 12 + 8.50 so $20.50
Payments 2-5 = $2.00
Final Payment = $28.50

can Anyone help me?

Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <form name="converter">
  3. <input type="text" value="0.00"  name="price"Price of Item
  4. <br>
  5.  
  6. <select name="shippingOptions" onchange="this.form.shippingPrice.value
  7. = this.options[this.selectedIndex].value; ">
  8. <option value="8.50">Ground - $8.50</option>
  9. <option value="10.50">3-Day - $10.50</option>
  10. <option value="14.50">2-Day - $14.50</option>
  11. <option value="24.00">Overnight - $24.00</option></select>
  12. <input type="text" value=""  name="shippingPrice">
  13.  
  14. <br>
  15. <br><br>
  16. <input type="button" value="Convert" onclick="javascript:calc()">
  17. <input type="reset" value="reset" onclick="javascript:calc()">
  18. <br><br>
  19. <input type="text" value=""  name="downpayment"Down Payment
  20. <br>
  21. <input type="text" value=""  name="payment2"Payment 2
  22. <br>
  23. <input type="text" value=""  name="payment3"Payment 3
  24. <br>
  25. <input type="text" value=""  name="payment4"Payment 4
  26. <br>
  27. <input type="text" value=""  name="payment5"Payment 5
  28. <br>
  29. <br>
  30. <input type="text" value=""  name="total"Total Amount Paid
  31.  
  32. </form>
  33.  
  34. <script language="javascript">
  35.  
  36. //calculate function
  37. function calc(){
  38.  
  39. //variables
  40. var price = document.converter.price.value
  41. var downpaymentdisplay = Math.round(price * .60)
  42. var payment2display = Math.round(price * .10)
  43. var payment3display = Math.round(price * .10)
  44. var payment4display = Math.round(price * .10)
  45. var payment5display = Math.round(price * .10)
  46.  
  47. var totaldisplay = Math.round(downpaymentdisplay + payment2display +
  48. payment3display + payment4display + payment5display)
  49.  
  50. //write in text box
  51. document.converter.downpayment.value=downpaymentdisplay
  52. document.converter.payment2.value=payment2display
  53. document.converter.payment3.value=payment3display
  54. document.converter.payment4.value=payment4display
  55. document.converter.payment5.value=payment5display
  56. document.converter.total.value=totaldisplay
  57.  
  58. }
  59. </script>
  60. </body>

Thanks
Yoni
Jun 27 '08 #1

✓ answered by suhasdhoke@gmail.com

On Jun 24, 11:08 pm, Yonih <Yoni.Hir...@gmail.comwrote:

You missed to add the selected shipping option's value to the
downpaymentdisplay var.
Try This...
Expand|Select|Wrap|Line Numbers
  1. var downpaymentdisplay = Math.round(price * .60)
Expand|Select|Wrap|Line Numbers
  1. var downpaymentdisplay = Math.round(price * .60)  +
  2. eval(document.converter.shippingOptions.value)
Expand|Select|Wrap|Line Numbers
  1. var totaldisplay = Math.round(downpaymentdisplay + payment2display +
  2. payment3display + payment4display + payment5display)
Expand|Select|Wrap|Line Numbers
  1. var totaldisplay = (downpaymentdisplay + payment2display +
  2. payment3display + payment4display + payment5display)
Cheers!!

Share this Question
Share on Google+
4 Replies


P: n/a
On Jun 24, 11:08 pm, Yonih <Yoni.Hir...@gmail.comwrote:

You missed to add the selected shipping option's value to the
downpaymentdisplay var.
Try This...
Expand|Select|Wrap|Line Numbers
  1. var downpaymentdisplay = Math.round(price * .60)
Expand|Select|Wrap|Line Numbers
  1. var downpaymentdisplay = Math.round(price * .60)  +
  2. eval(document.converter.shippingOptions.value)
Expand|Select|Wrap|Line Numbers
  1. var totaldisplay = Math.round(downpaymentdisplay + payment2display +
  2. payment3display + payment4display + payment5display)
Expand|Select|Wrap|Line Numbers
  1. var totaldisplay = (downpaymentdisplay + payment2display +
  2. payment3display + payment4display + payment5display)
Cheers!!
Jun 27 '08 #2

P: n/a
Thank you so much,

It works Great

Yoni
Jun 27 '08 #3

P: n/a
SO Hey I have anouther option to add to my calculator if anyone is
interested in the challange and helping me out a lot. Here is the
updated Calcualtor thanks to suhasdhoke.

These are the changes I need as you can see I have the date for the
first displaying field but I need the rest to be date +30 days,
+60,+90 and, +120.
Anychance someone knows how to do it?

Thanks

Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <form name="converter">
  3. <table width="0%" border="0">
  4. <tr>
  5. <td height="27">Enter Price of Item</td>
  6. <td><input type="text" value="0.00"  name="price"></td>
  7. </tr>
  8. <tr>
  9. <td>&nbsp;</td>
  10. <td><select name="shippingOptions"
  11. onchange="this.form.shippingPrice.value =
  12. this.options[this.selectedIndex].value; ">
  13. <option value="">Select Shipping</option>
  14. <option value="0.00">Ground - Free</option>
  15. <option value="10.50">3-Day - $10.50</option>
  16. <option value="14.50">2-Day - $14.50</option>
  17. <option value="24.00">Overnight - $24.00</option></select></td>
  18. </tr>
  19. </table>
  20.  
  21. <!-- Start Date Integration -->
  22. <Script type="text/javaScript">
  23. // Get today's current date.
  24. var now = new Date();
  25. // Array list of months.
  26. var months = new
  27. Array('January','February','March','April','May','June','July','August','September','October','November','December');
  28. // Calculate the number of the current day in the week.
  29. var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
  30. // Calculate four digit year.
  31. function fourdigits(number)   { return (number < 1000) ? number +
  32. 1900 : number; }
  33. // Join it all together
  34. today =  months[now.getMonth()] + " " + date + ", " +
  35. (fourdigits(now.getYear())) ;
  36. <!-- End Date Integration -->
  37. </script>
  38. <table width="268" border="0">
  39. <tr>
  40. <td width="205"><div align="right">
  41. <input type="button" value="Calculate"
  42. onclick="javascript:calc()">
  43. </div></td>
  44. <td width="10"></td>
  45. <td width="49"><input type="reset" value="reset"
  46. onclick="javascript:calc()"></td>
  47. </tr>
  48. </table>
  49. <br>
  50. <table width="0%" border="0">
  51. <tr>
  52. <td><div align="right">
  53. <script>document.write(today);</script>
  54. </div></td>
  55. <td<input type="text" value=""  name="downpayment"></td>
  56. </tr>
  57. <tr>
  58. <td><div align="right">Total + 30 Days</div></td>
  59. <td><input type="text" value=""  name="payment2"></td>
  60. </tr>
  61. <tr>
  62. <td><div align="right">Today + 60 Days</div></td>
  63. <td><input type="text" value=""  name="payment3"></td>
  64. </tr>
  65. <tr>
  66. <td><div align="right">Today + 90 Days</div></td>
  67. <td><input type="text" value=""  name="payment4"></td>
  68. </tr>
  69. <tr>
  70. <td><div align="right">Today + 120 Days</div></td>
  71. <td><input type="text" value=""  name="payment5"></td>
  72. </tr>
  73. <tr>
  74. <td><div align="right"></div></td>
  75. <td>&nbsp;</td>
  76. </tr>
  77. <tr>
  78. <td><div align="right">Total Amount Paid</div></td>
  79. <td><input type="text" value=""  name="total"></td>
  80. </tr>
  81. </table>
  82.  
  83.  
  84. <br>
  85. </form>
  86.  
  87. <script language="javascript">
  88.  
  89. //calculate function
  90. function calc(){
  91.  
  92. //variables
  93. var price = document.converter.price.value
  94. var downpaymentdisplay = Math.round(price * .60)  +
  95. eval(document.converter.shippingOptions.value)
  96. var payment2display = Math.round(price * .10)
  97. var payment3display = Math.round(price * .10)
  98. var payment4display = Math.round(price * .10)
  99. var payment5display = Math.round(price * .10)
  100.  
  101. var totaldisplay = Math.round(downpaymentdisplay + payment2display +
  102. payment3display + payment4display + payment5display)
  103. var totaldisplay = (downpaymentdisplay + payment2display +
  104. payment3display + payment4display + payment5display)
  105.  
  106. //write in text box
  107. document.converter.downpayment.value=downpaymentdisplay
  108. document.converter.payment2.value=payment2display
  109. document.converter.payment3.value=payment3display
  110. document.converter.payment4.value=payment4display
  111. document.converter.payment5.value=payment5display
  112. document.converter.total.value=totaldisplay
  113.  
  114. }
  115. </script>
  116. </body>
Jun 27 '08 #4

P: n/a
Never Mind I was able to work it out. Thanks
Yoni
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.