 |
HTML Help Please Search for the answer to your question before asking it! Thanks.
|
| View previous topic :: View next topic |
| Author |
Message |
kschmidt
Joined: 26 Sep 2008
Posts: 5
|
| Posted: Wed Oct 01, 2008 5:14 am does anybody have an idea. |
|
|
when i calculate it just adds the all numbers.
my calculator function should add A and B
but not D and E.
Does anybody have an idea.
thanks
<html>
<head>
<script type="text/javascript">
function calculate(form) {
var a = document.getElementById("purch").value;
var b = 1.50;
var c = a + b;
var d = 100;
var e = 10;
var f = a / d * e + a;
if (a <= 25) {
alert ("Your total is : " +c)
}
else {
alert ("Your total is : " +f)
}
}
</script>
</head>
<style type="text/css">
body {
color : #000E70;
background-color : #E3FFB4;
font-family : cursive;
font-size : 24pt;
font-weight : bold;
font-style : italic;
font-variant : normal;
text-align : center;
width : 50px;
height : 100px;
padding : 100px;
margin : 100px;
}
h1{
background-color : #BCF7FF;
color :#68001D;
border-width : 10px;
border-color : #9794FF;
}
</style>
<body>
<h1> Calculate your price and shipping here! </h1>
<form>
Purchased Item : <input type="text" name="purch" id="purch">
<input type="button" value="Calculate Total!" onClick="calculate(this.form)">
<div id="answer"></div>
</form>
</body>
</html> |
|
|
Straystudio
Joined: 14 Apr 2008
Posts: 264
Location: Nord Italy
|
| Posted: Mon Oct 27, 2008 2:33 am + may act as as math adding operator, as as string chaining |
|
|
kschmidt wrote: when i calculate it just adds the all numbers.
+ sign gets fooled and acts as chaining operator, not math; it does have indeed both capabilities.
Define variables so:
var a = document.getElementById("purch").value;
var b = 1.50;
var c = a*1 + b*1;
var d = 100;
var e = 10;
var f = (a / d * e)*1 + a*1;
where * multiplier operator (by 1) now forces the group to be a straight math sequence.
Wishes from Italy,
Enzo
|
|
|
| |
|
|
|
Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.19 © 2001, 2002 phpBB Group
|