M
mwh
Hi. If you remember, I posted Expressons Help. Now I am making a
calculator with javascript. I can't get this to work:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>Calculator</title>
<script language="Javascript">
<!-- Begin Hiding
var total = 0
var operator = 0
function calculate(number){
firm = document.form.value1
firm.value = firm.value + number
}
function operator(opvalue){
theoperator = opvalue
total = document.form.value1.value
document.form.sup.value = ""
}
function equals(){
currentDspvalue = eval(document.form.value1.value)
previousDspvalue = eval(total)
// add
if (theoperator == "+"){
answer = currentDspvalue + previousDspvalue
}
// divide
else if (theoperator == "/"){
answer = currentDspvalue / previousDspvalue
}
// multilply
else if (theoperator == "*"){
answer = currentDspvalue * previousDspvalue
}
// subtract
else if (theoperator == "-"){
answer = currentDspvalue - previousDspvalue
}
document.form.sup.value = answer
}
// -->
</script>
<body bgcolor="blue">
<form name="form">
<input name="value1" length=15 type="text"><br>
<input name="1" type="button" value="1" onClick="calculate(1)">
<input name="2" type="button" value="2" onClick="calculate(2)">
<input name="3" type="button" value="3" onClick="calculate(3)">
<input name="4" type="button" value="4" onClick="calculate(4)">
<input name="5" type="button" value="5" onClick="calculate(5)">
<input name="6" type="button" value="6" onClick="calculate(6)">
<input name="7" type="button" value="7" onClick="calculate(7)">
<input name="8" type="button" value="8" onClick="calculate(8)">
<input name="9" type="button" value="9" onClick="calculate(9)">
<input name="0" type="button" value="0" onClick="calculate(0)">
<input name="decimal" type="button" value=" . " onClick=calculate(".")>
<input name="plus" type="button" value="Plus" onClick =operator("+")>
<input name="minus" type="button" value="minus" onClick =operator("-")>
<input name="multiply" type="button" value="times" onClick
=operator("*")>
<input name="divide" type="button" value="divided by" onClick
=operator("/")>
<input name="equals" type="button" value=" = " onClick = "equals()">
<input name="reset" type="reset" value="clear">
</form>
</body>
</html>
It works fine until I press the equal button. Instead of displaying the
answer in the text area, It just says "Error on Page" in the status
bar.
Can Anyone help?
(____)
(\/)
/-------\/
/ | MWH ||
- ||----||
calculator with javascript. I can't get this to work:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>Calculator</title>
<script language="Javascript">
<!-- Begin Hiding
var total = 0
var operator = 0
function calculate(number){
firm = document.form.value1
firm.value = firm.value + number
}
function operator(opvalue){
theoperator = opvalue
total = document.form.value1.value
document.form.sup.value = ""
}
function equals(){
currentDspvalue = eval(document.form.value1.value)
previousDspvalue = eval(total)
// add
if (theoperator == "+"){
answer = currentDspvalue + previousDspvalue
}
// divide
else if (theoperator == "/"){
answer = currentDspvalue / previousDspvalue
}
// multilply
else if (theoperator == "*"){
answer = currentDspvalue * previousDspvalue
}
// subtract
else if (theoperator == "-"){
answer = currentDspvalue - previousDspvalue
}
document.form.sup.value = answer
}
// -->
</script>
<body bgcolor="blue">
<form name="form">
<input name="value1" length=15 type="text"><br>
<input name="1" type="button" value="1" onClick="calculate(1)">
<input name="2" type="button" value="2" onClick="calculate(2)">
<input name="3" type="button" value="3" onClick="calculate(3)">
<input name="4" type="button" value="4" onClick="calculate(4)">
<input name="5" type="button" value="5" onClick="calculate(5)">
<input name="6" type="button" value="6" onClick="calculate(6)">
<input name="7" type="button" value="7" onClick="calculate(7)">
<input name="8" type="button" value="8" onClick="calculate(8)">
<input name="9" type="button" value="9" onClick="calculate(9)">
<input name="0" type="button" value="0" onClick="calculate(0)">
<input name="decimal" type="button" value=" . " onClick=calculate(".")>
<input name="plus" type="button" value="Plus" onClick =operator("+")>
<input name="minus" type="button" value="minus" onClick =operator("-")>
<input name="multiply" type="button" value="times" onClick
=operator("*")>
<input name="divide" type="button" value="divided by" onClick
=operator("/")>
<input name="equals" type="button" value=" = " onClick = "equals()">
<input name="reset" type="reset" value="clear">
</form>
</body>
</html>
It works fine until I press the equal button. Instead of displaying the
answer in the text area, It just says "Error on Page" in the status
bar.
Can Anyone help?
(____)
(\/)
/-------\/
/ | MWH ||
- ||----||