Results 1 to 5 of 5

Thread: [RESOLVED] Javascript calculation

  1. #1

    Thread Starter
    Member Benderman's Avatar
    Join Date
    Mar 2011
    Location
    UK
    Posts
    61

    Resolved [RESOLVED] Javascript calculation

    Hi Guys,

    I'm trying to write some simple calculations using javascript in a web page. They don't work, can anyone see where I'm going wrong?

    HTML
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <!--Thanks to LGB for the basic site template-->
    <html>
    
    <head>
    <title>Simple Calculators</title>
    <meta name="Generator" content="TextPad 4.6">
    <meta name="Author" content="?">
    <meta name="Keywords" content="?">
    <meta name="Description" content="?">
    <link rel="stylesheet" type="text/css" href="simple.css">
    <script language = "javaScript" type="text/javascript" src="script01.js">
    </script>
    
    
    </head>
    
    <body>
    
    
    <!--This should be the same in all the pages just change the heading text. -->
    <div id="titlepart">
    	<h1>Simple Calculators</h1>
    	<hr /><br>
    </div>
    
    <div id="menupart">
    	<h3><a href="simplehome.htm">Home</a></h3>
    	<h3><a href="simplekanban.htm">Kan Ban</a></h3>
    	<h3><a href="simplesafety.htm">Safety Stock</a></h3>
    	<h3><a href="simplerol.htm">Re-order Levels</a></h3>
    	<h3><a href="simpleeoq.htm">EOQ</a></h3>
    	<h3><a href="simplecontact.htm">Contact</a></h3>
    </div>
    
    
    <!-- Edit this part ONLY -->
    <div id="mainpart">
    	<h2>Re-Order Level (ROL)</h2>
    	<p>The ROL is used to deterime a point at which an order is placed for material. This in itself is a very simple calculation using the 	average demand, lead time and safety stock previously calculated.</p>
    	<p>It is often used in conjuction with the Economic Order Quantity (EOQ) which helps to determine how much to order.</p>
    	<br />
    
    <form name="frmOne">
    <p><label>Safety Stock:<input type="text" size="10" name="txtsafety"/></label></p>
    <p><label>Average Demand:<input type="text" size="10" name="txtdemand"/></label></p>
    <p><label>Standard Lead Time:<input type="text" size="10" name="txtleadtime"/></label></p>
    <p><label><input type="Button" value="Calculate" size="50" onClick="calculate()"/></label></p>
    <p><label>Result<input type="Text"  size="10" name="txtresult" /></label></p>
    </form>
    
    
    </div>
    
    </body>
    
    </html>
    And Javascript:

    Code:
    function calculate() {
    
    var A = parseFloat(document.formOne.txtsafety.value);
    var B = parseFloat(document.formOne.txtdemand.value);
    var C = parseFloat(document.formOne.txtleadtime.value);
    
    
    
    document.frmOne.txtresult.value = A+(B*C);
    
    }
    Any ideas/tips would be welcome.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Javascript calculation

    what's the problem? what happens when you press your button?
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Member Benderman's Avatar
    Join Date
    Mar 2011
    Location
    UK
    Posts
    61

    Re: Javascript calculation

    Nothing at all happens when I push the button. I'm really stumped here.

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Javascript calculation

    document.formOne cannot be found.

    You reference formOne in your javascript, but frmOne is what the form is actually called.

  5. #5

    Thread Starter
    Member Benderman's Avatar
    Join Date
    Mar 2011
    Location
    UK
    Posts
    61

    Re: Javascript calculation

    Thank you! I guess I just got blind to it, a bit of a noob error.

    It works now.

    Thanks again.

    Ben

Posting Permissions

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



Click Here to Expand Forum to Full Width