How can I create a simpler JavaScript code for clicking buttons to input letters into a text box? Instead of creating getElementByID for each button, is it possible to use some kind of loop?
<div id="alpha" >
<br/>
<div align="center">
<button id="q" class="letters">Q</button>
</div>
<div align="center">
<button id="w" class="letters" onclick="theclick()">W</button>
</div>
<div align="center">
<button id="e" class="letters">E</button>
</div>
<div align="center">
<button id="r" class="letters">R</button>
</div>
<div align="center">
<button id="t" class="letters">T</button>
</div>
**INITIAL JAVASCRIPT WITH ONLY THE ONCLICK FUNCTION FOR BUTTON "W"**
What's the best way to simplify this JavaScript code without having an onClick function for every single button?
<script>
function theclick() {
var x = document.getElementByClassName("letters").innerHTML;
document.getElementById("textbox").value = x;
};
</script>