I created a virtual keyboard and am trying to fill in the input field with the letters that appear on the button. I have the following functions:
This function takes a character and makes it a char button as its value:
function keyButton(char) {
var btn = document.createElement("button");
btn.innerText = char;
btn.id = "btn";
keyStroke()
return btn;
}
This function creates a button for all letters:
var keyList = "QWERTYUIOPASDFGHJKLZXCVBNM";
for (i in keyList)
{
var button = keyButton(keyList[i]);
document.body.appendChild(button)
}
This function is a problem, it should read the value from the button and add it to the input field:
function keyStroke() {
document.getElementById("searchBar").value += document.getElementById("btn").innerText;
}
The HTML for the input field looks like this:
<input id="searchBar" class="inputBar" placeholder="Enter something" />
source
share