Forum Moderators: open
I have a form where someone will enter a number, say "25" lets call this field "L". They will then press the calculate key and 4 different answers will appear.
#1 - will be the answer of 25*2.05
#2 - will be the answer of 25*1.99
#3 - will be the answer of 25*1.62
#4 - will be the answer of 25*.95
If someone could help me out and explain how I should write this I would appreciate it.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
<title></title>
<script type="text/javascript">
function calculate() {
var L = document.getElementById('L');
// You should add a check here to make sure the value is numeric
var str = "";
str += "#1 " + L.value + " * 2.05 = " + (L.value * 2.05);
str += "\n#2 " + L.value + " * 1.99 = " + (L.value * 1.99);
str += "\n#3 " + L.value + " * 1.62 = " + (L.value * 1.62);
str += "\n#4 " + L.value + " * 0.95 = " + (L.value * 0.95);
alert(str);
}
function init() {
// Attach behaviors
var calc = document.getElementById('calc');
calc.onclick = calculate;
}
window.onload = init;
</script>
</head>
<body>
<form action="">
<div>
<input type="text" id="L">
<input type="button" id="calc" value="Calculate">
</div>
</form>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
<title></title>
<script type="text/javascript">
function calculate() {
var L = document.getElementById('L');
// You should add a check here to make sure the value is numeric
var str = "";
str += "#1 " + L.value + " * 2.05 = " + (L.value * 2.05);
str += "<br>#2 " + L.value + " * 1.99 = " + (L.value * 1.99);
str += "<br>#3 " + L.value + " * 1.62 = " + (L.value * 1.62);
str += "<br>#4 " + L.value + " * 0.95 = " + (L.value * 0.95);
document.getElementById('answerDiv').innerHTML=str;
}
function init() {
// Attach behaviors
var calc = document.getElementById('calc');
calc.onclick = calculate;
}
window.onload = init;
</script>
</head>
<body>
<form action="">
<div>
<input type="text" id="L">
<input type="button" id="calc" value="Calculate">
</div>
<div id="answerDiv">
<br>
<br>
<br>
</div>
</form>
</body>
</html>