I need help with a javascript function for dynamic prices!!!

Discussion in 'JavaScript' started by Sarcastr0, Jul 8, 2009.

  1. #1
    I am trying to find a function that will allow me to take an equation, and post the output in another location. For example.

    x * y + z = output

    I need to get the output to display in a certain section of the website. Anybody know a java script function that will do what I need???
     
    Sarcastr0, Jul 8, 2009 IP
  2. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Yes you can.
    Create an div element in the location of output(say, name="myDiv").
    On clicking a "get equation result" button call the following function.
    Hope i have answered your question.
    If not, do reply.
     
    Unni krishnan, Jul 8, 2009 IP
  3. xylitol

    xylitol Banned

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi
    Please try my script:
    <html>
    <head>
    <title></title>
    <script language="JavaScript">
    <!--
    
    function add()
    {
        var num1, num2, num3, total;
        num1 = parseInt(document.calcForm.num1.value);
        num2 = parseInt(document.calcForm.num2.value);
        num3 = parseInt(document.calcForm.num3.value);
    
    	var sum = (num1*num2)+num3;
      
        document.calcForm.output.value = sum;
    }
      
    </script>
    </head>
    
    <body>
    <form name="calcForm">
    <p>Enter the X Factor:
    <br /><input type="text" name="num1" size="5" align="center"></p>
    <p>Enter the Y Factor:
    <br /><input type="text" name="num2" size="5" align="center"></p>
    <p>Enter the Z Factor:
    <br /><input type="text" name="num3" size="5" align="center"></p>
    <p><input type="button" value="Submit" onClick="add()">
    <br />( X x Y ) + Z is = <input type="text" name="output"size="10"  style="border:0" readonly></p>
    
    </body>
    </html>
    Code (markup):
    Hope it can help you
     
    xylitol, Jul 10, 2009 IP