Click to See Complete Forum and Search --> : 1textbox + 2ndtexbox = sum?


Sux0rZh@jc0rz
08-28-2003, 05:18 PM
I've been trying to get a simple simple simple math thing going. I'v looked at some calculator scripts but they are to big to find what i need in them=/ I've also messed around with www.w3schools.com/js/default.asp and didn't find it there....how can i make one textbox add with one below it and have the sum show up in a textbox below that using these values?:

<html>
<head>
</head>
<body>

<form name="form1">
<input type="text" name="text1"> <br>
<input type="text" name="text2"> <br>
<input type="text" name="outcome" readonly>
</form>

</body>
</html>

I know this sounds newbish but I must have tried to do it a million and a half ways and the blind man just can't see.

Exuro
08-28-2003, 05:35 PM
It'd be interesting to see what you've been trying... But anyway, here's how your form should look:
<form name="form1" onsubmit="return getSum();">
<input type="text" name="text1"> +
<input type="text" name="text2">
<input type="submit" value="=">
<input type="text" name="outcome" readonly>
</form>
And here's the JavaScript to go along with it:
<script type="text/javascript">
<!--
function getSum() {
var num1 = parseFloat(document.form1.text1.value);
var num2 = parseFloat(document.form1.text2.value);
document.form1.outcome.value = num1 + num2;
return false;
}
//-->
</script>