robcrozier Posted June 20, 2008 Share Posted June 20, 2008 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 More sharing options...
technotool Posted June 20, 2008 Share Posted June 20, 2008 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 https://forums.phpfreaks.com/topic/111083-adding-the-values-in-form-fields/#findComment-570118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.