Jump to content

Adding the values in form fields


robcrozier

Recommended Posts

Hi guys.

 

I wonder if any of you can help me with what i think is a basic piece of code.  Basically, i have three form fields which accept numeric data and i would like to add the first two and then subtract the third and output the result in real time on the browser.  I just can't seem to find what I'm looking for in Google etc.

 

Any help would be appreciated!

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/111083-adding-the-values-in-form-fields/
Share on other sites

this should get you about 80% there.

 

<html>
<head>
<script>
function addUp(){
var one, two, three

one = document.getElementById("boxone").value;
two = document.getElementById("boxtwo").value;
three=document.getElementById("boxthree").value;


var sum = ( Math.abs(one) + Math.abs(two) ) - Math.abs(three)

alert(sum);
}


</script>
</head>
<form name="boxaddup">
a<input type="text" id="boxone" size="3"><br>
b<input type="text" id="boxtwo" size="3"><br>
c<input type="text" id="boxthree" size="3" onChange="addUp()"><br>


</form>


</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.