/    Sign up×
Community /Pin to ProfileBookmark

Calculating Price from Quantity selected by the user

ok so i have this form on my web page.

[code=html]<div id=”purhcaseForm”>
<form id=”purchase”>
<br> Item Price: $463.50
<br> Please Select Quantity
<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’ />[/code]

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 ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsAug 26.2013 — [CODE]<!DOCTYPE html>
<html lang="en">
<head>
<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>
</head>
<body>
<div class="slider-vertical"></div>
<div id="purhcaseForm">
<form id="purchase">
<br> Item Price: $463.50
<br> Please Select Quantity
<input type='button' name='subtract' onclick='Total("qty",-1,"total",463.50);' value='-'/>
<input type='button' name='add' 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>[/CODE]
Copy linkTweet thisAlerts:
@spazzo246authorAug 27.2013 — 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?

[code=html]<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>[/code]







I want to get some sort of basic understanding as to what you did. Thanks apreciate all your help
Copy linkTweet thisAlerts:
@PadonakAug 27.2013 — Vic, i can't believe my eyes you're using inline onclicks
×

Success!

Help @spazzo246 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...