...

View Full Version : Resolved HELP!! Javascript Calculator



Spaull69
07-29-2009, 12:20 PM
Hi People

I need some help

I have some simple calculators I have developed for pricing etc of items.

I had a request to change it to enable the shipping to be manually added.

But now the calc does not work. iT WORKED BEFORE WHEN IT WAS LESS COMPLICATED.

The calc does not appear to be adding the shipping value unless the initial value is 0.

Can anyone help

Thanks!



<html>

<head>
<SCRIPT LANGUAGE="JavaScript">

function calc(form) {
form.result.value=((form.expr.value)*1.57/1.262*1.1)*((form.expr0.value)/-100+1);
var newnumber = Math.round(form.result.value*Math.pow(10,0))/Math.pow(10,0);
document.FrontPage_Form1.result.value = newnumber;;
form.incship.value=((form.expr.value)*1.57/1.262*1.1)*((form.expr0.value)/-100+1)+(form.ship.value);
var newnumber1 = Math.round(form.incship.value*Math.pow(10,0))/Math.pow(10,0);
document.FrontPage_Form1.incship.value = newnumber1;;
}
function calc1(form) {
form.result.value=((form.expr1.value)/1.262*1.1)*((form.expr0.value)/-100+1);
var newnumber = Math.round(form.result.value*Math.pow(10,0))/Math.pow(10,0);
document.FrontPage_Form1.result.value = newnumber;;
form.incship.value=((form.expr1.value)/1.262*1.1)*((form.expr0.value)/-100+1)+(form.ship.value);
var newnumber1 = Math.round(form.incship.value*Math.pow(10,0))/Math.pow(10,0);
document.FrontPage_Form1.incship.value = newnumber1;;
}
</SCRIPT>
</head>
<body style="text-align: center">
<font face="Arial" size="2">Please Enter the Information Below<br>
</font>
<form onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1">
<table border=3 cellspacing=2 cellpadding=5>
<tr>
<td align=center><b><i><font face="Arial" size="2"> Transfer </font></i>
<font face="Arial" size="2"><i>Repair Cost</i></font></b></td>
</tr>
<tr>
<td align=center><font face="Arial"><input type=text name=expr size=15></font></td>
</tr>
<tr>
<td align=center>
<font face="Arial">
<input type=button value="Calculate From Transfer Price" onclick="calc(this.form)" style="font-size: 10pt; font-family: Arial"></font></td>
</tr>
<tr>
<td align=center>
<p style="margin-top: 0; margin-bottom: 0"><font face="Times New Roman" size="2">
</font>
<font face="Arial" size="2">Repair List Price</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Arial" style="font-size: 7pt">(Only use when Transfer price is not
available)</font></td>
</tr>
<tr>
<td align=center><font face="Arial"><input type=text name=expr1 size=15></font></td>
</tr>
<tr>
<td align=center><font size="1" face="Arial">
<input type=button value="Calculate From Repair List Price" onclick="calc1(this.form)" style="font-family: Arial; font-size: 10pt"></font></td>
</tr>
<tr>
<td align=center><font face="Arial" size="2"><i>Customers Discount (%)</i></font></td>
</tr>
<tr>
<td align=center><font face="Arial"><input type=text name=expr0 size=15 value="0"></font></td>
</tr>
<tr>
<td align=center>
<p style="margin-top: 0; margin-bottom: 0"><i><font face="Arial" size="2">
Customer Repair Price</font></i></p>
<p style="margin-top: 0; margin-bottom: 0"><b><i><font face="Arial" size="2">(exc
shipping costs)</font></i></b></td>
</tr>
<tr>
<td align=center>
<p style="margin-top: 0; margin-bottom: 0"><font size="5" face="Arial"></font><font face="Arial"><input type=text name=result size=15></font></td>
</tr>
<tr>
<td align=center>
<i><font face="Arial" size="2">Shipping Cost (60 standard shipping charge)</font></i></td>
</tr>
<tr>
<td align=center>
<font size="5" face="Arial"></font><font size="1" face="Arial"> <input type=text name=ship size=15 value="60"></font></td>
</tr>
<tr>
<td align=center>
<i><font face="Arial" size="2">Customer Repair Price</font></i><p style="margin-top: 0; margin-bottom: 0"><b><i><font face="Arial" size="2">(inc
shipping costs)</font></i></b></td>
</tr>
<tr>
<td align=center>
<p style="margin-top: 0; margin-bottom: 0">
<font size="5" face="Arial"></font><font face="Arial"><input type=text name=incship size=15></font></td>
</tr>
</table>
</form>


</body>

</html>

Philip M
07-29-2009, 02:08 PM
form.incship.value=((form.expr.value)*1.57/1.262*1.1)*((form.expr0.value)/-100+1)+parseFloat(form.ship.value);

As input form.ship.value is a string, not a number.


<script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead.

Instead of the cumbersome
Math.round(form.result.value*Math.pow(10,0))/Math.pow(10,0);
use
parseInt(form.result.value);
or Math.round(form.result.value);


“Get your facts first, and then you can distort them as much as you please: facts are stubborn, but statistics are more pliable”. - Mark Twain



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum