Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question HELP!! Javascript Calculator

    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!

    Code:
    <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>
    Last edited by Spaull69; 07-29-2009 at 03:50 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,147
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    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
    Last edited by Philip M; 07-29-2009 at 02:12 PM.

  • Users who have thanked Philip M for this post:

    Spaull69 (07-29-2009)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •