Jump to content

instant addition puzzle


loquela

Recommended Posts

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>

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.