You did a couple of things incorrectly.
First of all, the input value must be read at a certain time. For example, when a button is pressed, when the input field's value changes or similar situations. In your case, it was read as soon as the document was parsed, when the input field did not have any value.
Second, you did not write the result to the output field.
This line var CALC3 = OUTPUT1;
redeclares the CALC3 variable and gives it the value OUTPUT1. What you want is to set the value of the field OUTPUT1 as CALC3
Try this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transititonal//EN"
""http://www.w3.org/TR/XHTML1/DTD/xhtml1-transitional.dtd">
<html>
<head></head>
<body>
<form name="TESTING">
<table border="1" width="600" height="200" cellpadding="10" cellspacing="3">
<tr><th colspan="2"><h1>TESTING</h1></th></tr>
<tr> <th><h3>INPUT</h3></th>
<th><h3>OUTPUT</h3></th> </tr>
<tr></tr>
<td><input type="number" name="INPUT1" id="input" onchange="calculate();"/></td>
<td><input type="number" name="OUTPUT1" id="output"></td>
<table>
</form>
<script type="text/javascript">
function calculate() {
var USERINPUT1 = document.TESTING.INPUT1.value;
var CALC1 = USERINPUT1/20;
var CALC2 = CALC1*.585;
var CALC3 = CALC2*.30;
document.TESTING.OUTPUT1.value = CALC3;
}
</script>
</body>
</html>
When the value from the first input field changes, it calls the function calculate() (onchange="calculate();"
) and then automatically updates the second field (you write the value just like you read it document.TESTING.OUTPUT1.value = CALC3;
).
[edit]
The first version of the code is pretty much like yours, so you will be able to understand it more easily, but you should also take a look at this. You had some misplaced table row tags and some untidy code, so I also cleaned it up a little. It's still far from best practice, but it's an improved version of your page
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<form name="TESTING">
<table border="1" width="600" height="200" cellpadding="10" cellspacing="3">
<tr>
<th colspan="2">
<h1>TESTING</h1>
</th>
</tr>
<tr>
<th>
<h3>INPUT</h3>
</th>
<th>
<h3>OUTPUT</h3>
</th>
</tr>
<tr>
<td>
<input type="number" name="INPUT1" id="input" onchange="calculate();"/>
</td>
<td>
<input type="number" name="OUTPUT1" id="output">
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function calculate() {
var USERINPUT1 = document.TESTING.INPUT1.value,
RESULT = (USERINPUT1/20) * .585 * .30;
document.TESTING.OUTPUT1.value = RESULT;
}
</script>
</body>
</html>