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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.