# Thread: Calculating Price from Quantity selected by the user

1. Registered User
Join Date
Aug 2013
Posts
2

## Calculating Price from Quantity selected by the user

ok so i have this form on my web page.

HTML Code:
<div id="purhcaseForm">
<form id="purchase">
<br> Item Price: \$463.50
<input type='button' name='subtract' onclick='javascript: document.getElementById("qty").value--;' value='-'/>
<input type='button' name='add' onclick='javascript: document.getElementById("qty").value++;' value='+'/>
<input type='text' name='qty' id='qty' />
what i want to do is in the simplest way possible is to have another box which outputs the total order price taking into account the quantity the user has specified. im very new to java script and do not have any clue as to where to start ( i dont even know if what i have is the best way of achieving my objective) all help is apreciated

2. Super Moderator
Join Date
Jun 2004
Location
Portsmouth UK
Posts
2,709
Code:
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<script>
function Total(qty,ud,total,value){
qty=document.getElementById(qty);
ud>0?qty.value++:qty.value--;
qty.value=Math.max(qty.value,0);
document.getElementById(total).value=qty.value*value;
}
</script>
<body>
<div class="slider-vertical"></div>
<div id="purhcaseForm">
<form id="purchase">
<br> Item Price: \$463.50
<input type='button' name='subtract' onclick='Total("qty",-1,"total",463.50);' value='-'/>
<input type='text' name='qty' id='qty' readonly=true value="0"/>
<input type='text' name='total' id='total' value="0" />
</form>
</div>
</body>
</html>

3. Registered User
Join Date
Aug 2013
Posts
2

## Re: Calculating Price from Quantity selected by the user

Hi, thats exactly what i wanted. if its to much trouble dw about it but can you briefly explain what this part of the code does?

HTML Code:
<script>
function Total(qty,ud,total,value){
qty=document.getElementById(qty);
ud>0?qty.value++:qty.value--;
qty.value=Math.max(qty.value,0);
document.getElementById(total).value=qty.value*value;
}
</script>

I want to get some sort of basic understanding as to what you did. Thanks apreciate all your help

4. Vic, i can't believe my eyes you're using inline onclicks