Click here to Skip to main content
14,641,739 members
Rate this:
Please Sign up or sign in to vote.
See more:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Tip Calculator Application</title>
<script>
function tipCalculate(slider,bill,total){
    var tip = document.getElementById('tip');
    var slideval = document.getElementById('slideval');
    var bill = document.getElementById(bill).value;
    var prcnt = slider * .01;   
    var total = tip + bill;
    total.innerHTML = " $ " +(tip + bill).toFixed(2);
    tip.innerHTML = " $ "+(bill * prcnt).toFixed(2);
    slideval.innerHTML = slider+"%";
}
</script>
</head>
<body>
<h2>Tip Calculator</h2>
Amount: $
<input type="text" id="bill"><br>
Tip Percentage: 
<input type="range" min="0" max="100" value="0" step="1" onchange="tipCalculate(this.value,'bill')" style="width:300px;">
<span id="slideval">0%</span>
<p>Tip =<span id="tip"></span></p>
<p>Total =<span id="total"></span></p>
</body>
</html>
Posted
Updated 11-Sep-13 10:03am
v2
Comments
ridoy 11-Sep-13 16:57pm
   
and the question is?!

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I don't think a calculator with "total" makes any practical sense at all — too ad-hoc. JavaScrip is such a thing… this is already a calculator, thanks to the wonderful function eval. You can allow the user to write any kinds of expression in a text area and evaluate it, handle exceptions and so on. Please see my recent answer: visual studio JavaScript problem please help!![^].

And this is a code sample: http://sakryukov.org/freeware/calculator/[^].

—SA
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100