loquela Posted April 16, 2010 Share Posted April 16, 2010 Hi there, I am looking for a script that will instantly add up the totals from 5 input fields and display the sum of each field on screen as the user types in the values. Any ideas? Thanks in advance! L. Quote Link to comment https://forums.phpfreaks.com/topic/198746-instant-addition-puzzle/ Share on other sites More sharing options...
Ken2k7 Posted April 17, 2010 Share Posted April 17, 2010 Create a function that adds up the numbers. Then bind each input field to the function using onkeyup. Here's an example: Number 1: <input type="text" id="it1" onkeyup='add();' /><br /> Number 2: <input type="text" id="it2" onkeyup='add();' /><br /> Answer: <span id='answer'></span> <script type='text/javascript'> function add(){document.getElementById('answer').innerHTML = ((int) document.getElementById('it1').value) + ((int) document.getElementById('it2').value);} </script> Quote Link to comment https://forums.phpfreaks.com/topic/198746-instant-addition-puzzle/#findComment-1043587 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.