/    Sign up×
Community /Pin to ProfileBookmark

Update price + discount

Hello there, I’m working on a web site, where customer select one size of pizza from radio buttons. The size has different prices depending of what radio button customer select. at the bottom, customer will see a text box where price will be display. then if customer is student will receive a 10% off of discount, checking a box and price will be decrease.| My problem is the follow: I don’t know how to calculate % off, updating the price.
Javascript:

[code=html]function updateTotal()
{
var sizeAll = document.getElementsByName(‘product’);
var i = sizeAll.length;
var size = 0;
var topAll = document.getElementsByName(‘discount’);
var c = topAll.length;
var top = 0;
var total = document.getElementById(‘total’);

while(i–)
{
if(sizeAll[i].checked)
{
size = parseFloat(sizeAll[i].value);
}
}

if(size > 0)
{

while(c–)
{
if(topAll[c].checked)
{
top += parseFloat(topAll[c].value);
}
}

total.value = ((size / 100) * top).toFixed(2);
}
else
{
total.value = size;

}
return true;
}
[/code]

Html Form:

[code=html]Pizza Size: (Small 5 Euro- Medium 8 Euro- Large 12 Euro)
<td id=”radios” >
<input type=”radio” name=”product” value=”5.00″ onclick=”updateTotal()”>Small(10″)
<input type=”radio” name=”product” value=”8.00″ onclick=”updateTotal()”>Medium(12″)
<input type=”radio” name=”product” value=”12.00″ onclick=”updateTotal()”>Large(14″)

Student receive a 10% discount.
<td id=”checkboxes” >
<input type=”checkbox” name=”discount” onclick=”updateTotal()” value=”0.10″>

Total Cost:
<input type=”text” name=”total” id=”total” size=”10″ readonly=”readonly”>
[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @TheML 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.10,
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,
)...