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 Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.