Subtract 2 Entries (Floats)

[Total: 0    Average: 0/5]

This shows how to convert 2 strings into floats and subtract them and display the result into another text component of a form.

Body Code:

<form name=exf1>
<BR><input type=text name=n1 value="34.12">
<BR><input type=text name=n2 value="1.05">
<BR><input type=text name=r1 value="?">
<BR><input type=button value="Subtract" onclick="subIt()">
</form>
<script type=text/javascript>
function subIt() {
var n1 = parseFloat(document.exf1.n1.value);
var n2 = parseFloat(document.exf1.n2.value);
document.exf1.r1.value = n1-n2;
}
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *