Need Help with Calculator Java Script

Y

Yonih

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?

<body>
<form name="converter">
<input type="text" value="0.00" name="price"> Price of Item
<br>

<select name="shippingOptions" onchange="this.form.shippingPrice.value
= this.options[this.selectedIndex].value; ">
<option value="8.50">Ground - $8.50</option>
<option value="10.50">3-Day - $10.50</option>
<option value="14.50">2-Day - $14.50</option>
<option value="24.00">Overnight - $24.00</option></select>
<input type="text" value="" name="shippingPrice">

<br>
<br><br>
<input type="button" value="Convert" onclick="javascript:calc()">
<input type="reset" value="reset" onclick="javascript:calc()">
<br><br>
<input type="text" value="" name="downpayment"> Down Payment
<br>
<input type="text" value="" name="payment2"> Payment 2
<br>
<input type="text" value="" name="payment3"> Payment 3
<br>
<input type="text" value="" name="payment4"> Payment 4
<br>
<input type="text" value="" name="payment5"> Payment 5
<br>
<br>
<input type="text" value="" name="total"> Total Amount Paid

</form>

<script language="javascript">

//calculate function
function calc(){

//variables
var price = document.converter.price.value
var downpaymentdisplay = Math.round(price * .60)
var payment2display = Math.round(price * .10)
var payment3display = Math.round(price * .10)
var payment4display = Math.round(price * .10)
var payment5display = Math.round(price * .10)

var totaldisplay = Math.round(downpaymentdisplay + payment2display +
payment3display + payment4display + payment5display)

//write in text box
document.converter.downpayment.value=downpaymentdisplay
document.converter.payment2.value=payment2display
document.converter.payment3.value=payment3display
document.converter.payment4.value=payment4display
document.converter.payment5.value=payment5display
document.converter.total.value=totaldisplay

}
</script>
</body>


Thanks
Yoni
 
S

suhasdhoke

You missed to add the selected shipping option's value to the
downpaymentdisplay var.
Try This...
var downpaymentdisplay = Math.round(price * .60)

var downpaymentdisplay = Math.round(price * .60) +
eval(document.converter.shippingOptions.value)
var totaldisplay = Math.round(downpaymentdisplay + payment2display +
payment3display + payment4display + payment5display)

var totaldisplay = (downpaymentdisplay + payment2display +
payment3display + payment4display + payment5display)

Cheers!!
 
Y

Yonih

Thank you so much,

It works Great

Yoni

You missed to add the selected shipping option's value to the
downpaymentdisplay var.
Try This...


var downpaymentdisplay = Math.round(price * .60)  +
eval(document.converter.shippingOptions.value)


var totaldisplay = (downpaymentdisplay + payment2display +
payment3display + payment4display + payment5display)

Cheers!!
 
Y

Yonih

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

<body>
<form name="converter">
<table width="0%" border="0">
<tr>
<td height="27">Enter Price of Item</td>
<td><input type="text" value="0.00" name="price"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><select name="shippingOptions"
onchange="this.form.shippingPrice.value =
this.options[this.selectedIndex].value; ">
<option value="">Select Shipping</option>
<option value="0.00">Ground - Free</option>
<option value="10.50">3-Day - $10.50</option>
<option value="14.50">2-Day - $14.50</option>
<option value="24.00">Overnight - $24.00</option></select></td>
</tr>
</table>

<!-- Start Date Integration -->
<Script type="text/javaScript">
// Get today's current date.
var now = new Date();
// Array list of months.
var months = new
Array('January','February','March','April','May','June','July','August','September','October','November','December');
// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
// Calculate four digit year.
function fourdigits(number) { return (number < 1000) ? number +
1900 : number; }
// Join it all together
today = months[now.getMonth()] + " " + date + ", " +
(fourdigits(now.getYear())) ;
<!-- End Date Integration -->
</script>
<table width="268" border="0">
<tr>
<td width="205"><div align="right">
<input type="button" value="Calculate"
onclick="javascript:calc()">
</div></td>
<td width="10"></td>
<td width="49"><input type="reset" value="reset"
onclick="javascript:calc()"></td>
</tr>
</table>
<br>
<table width="0%" border="0">
<tr>
<td><div align="right">
<script>document.write(today);</script>
</div></td>
<td> <input type="text" value="" name="downpayment"></td>
</tr>
<tr>
<td><div align="right">Total + 30 Days</div></td>
<td><input type="text" value="" name="payment2"></td>
</tr>
<tr>
<td><div align="right">Today + 60 Days</div></td>
<td><input type="text" value="" name="payment3"></td>
</tr>
<tr>
<td><div align="right">Today + 90 Days</div></td>
<td><input type="text" value="" name="payment4"></td>
</tr>
<tr>
<td><div align="right">Today + 120 Days</div></td>
<td><input type="text" value="" name="payment5"></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="right">Total Amount Paid</div></td>
<td><input type="text" value="" name="total"></td>
</tr>
</table>


<br>
</form>

<script language="javascript">

//calculate function
function calc(){

//variables
var price = document.converter.price.value
var downpaymentdisplay = Math.round(price * .60) +
eval(document.converter.shippingOptions.value)
var payment2display = Math.round(price * .10)
var payment3display = Math.round(price * .10)
var payment4display = Math.round(price * .10)
var payment5display = Math.round(price * .10)

var totaldisplay = Math.round(downpaymentdisplay + payment2display +
payment3display + payment4display + payment5display)
var totaldisplay = (downpaymentdisplay + payment2display +
payment3display + payment4display + payment5display)

//write in text box
document.converter.downpayment.value=downpaymentdisplay
document.converter.payment2.value=payment2display
document.converter.payment3.value=payment3display
document.converter.payment4.value=payment4display
document.converter.payment5.value=payment5display
document.converter.total.value=totaldisplay

}
</script>
</body>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top