How to append button value to end of text box when button is pressed

I’m not afraid to admit that I am absolutely helpless when it comes to JavaScript. I can’t for the life of me write even the simplest of scripts on my own.

What I’m trying to do is replicate the iPhone’s keypad screen. So when someone clicks on the number 1 button, a 1 is appended to the input box above. I have it working in jQuery, but the tablet that is displaying the page is slow to react to each button press. I was hoping if I could have the same functionality without having to load jQuery it may speed things up a bit.

Thanks

Nevermind. Please disregard. As soon as I posted this I continued to Google this topic and found exactly what I needed.

If you had a number field and a button called “three”


<input id="numbers" type="text">
...
<button id="three">3</button>

You can attach an onclick event to the button, which would update the number input.


function addContentToNumbers() {
    document.getElementById('number').value += this.innerHTML;
}

var button = document.getElementById('three');
button.onclick = addContentToNumbers;