SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript calculation - form

    Hi

    I've just started learn javascript and I have problem like this one.
    I want to first multiply product by quantity and later add it to overall sum.
    Can anyone help?
    Code:
    <html>
    	<head>
    		<title></title>
    		
    		<script language="javascript" type="text/javascript" src="test.js">
    		</script>
    	</head>
    <body>
    <form>
    <p>
    	 Your order: <span id="result"></span><br /><br />
    	 Order total: <span id="orderTotal"></span><br /><br />
    	
    	Price: 10<input type="hidden" id="value0" value="10"/>
    	Quantity:<input type="text" id="qty" size="2" value=""/>	
    	<input type="button" onclick="calculate();" value="Add"/>
    	<br/>
    	Price: 20<input type="hidden" id="value1" value="20"/>
    	Quantity:<input type="text" id="qty"  size="2" value=""/>	
    	<input type="button" onclick="calculate();" value="Add"/>	
    	<br/>
    	Price: 30<input type="hidden" id="value2" value="30"/>
    	Quantity:<input type="text" id="qty" size="2" value=""/>	
    	<input type="button" onclick="calculate();" value="Add"/>
    
    </form>    				
        			
    </body>
    </html>
    
    function calculate()
    {
    	var qty = document.getElementById("qty").value;
    	var value = document.getElementById("value0").value;
    	
    	var result =  value * qty;
    		
    	document.getElementById("result").innerHTML = result;	
    }
    Last edited by felgall; Dec 23, 2011 at 13:25.


Bookmarks

Posting Permissions

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