I am trying to write what should be an incredibly easy script and cannot get it working on either Mozilla or IE.
Description:
1. User enters a number in the first textfield representing ounces.
2. User clicks out of the textfield and the number is converted from ounces to grams in a second textfield.
Sounds easy, but I cannot get it working for some reason. Can someone help me. I plan on adding approx 5 or 6 more conversions to the same form.
Below is the html I have been using:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript" language="Javascript">
function calc(val,factor,result) {
test = val.value*factor
test2 = test.toPrecision(4)
document.forms.converter.result.value = test2
}
</script>
</head>
<body>
<form name="converter">
<input name="floz" type="text" onchange="calc(this, 28.349523125, 'grams')"> oz
<input name="grams" type="text">
</form>
</body>
</html>
Description:
1. User enters a number in the first textfield representing ounces.
2. User clicks out of the textfield and the number is converted from ounces to grams in a second textfield.
Sounds easy, but I cannot get it working for some reason. Can someone help me. I plan on adding approx 5 or 6 more conversions to the same form.
Below is the html I have been using:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript" language="Javascript">
function calc(val,factor,result) {
test = val.value*factor
test2 = test.toPrecision(4)
document.forms.converter.result.value = test2
}
</script>
</head>
<body>
<form name="converter">
<input name="floz" type="text" onchange="calc(this, 28.349523125, 'grams')"> oz
<input name="grams" type="text">
</form>
</body>
</html>