/    Sign up×
Community /Pin to ProfileBookmark

Making an onscreen keyboard with HTML

Hey there, I am currently trying to make a little, simple music player for university with a search feature and for that I need to make on screen keyboard. I’ve layed out the buttons but I’m not sure what else I can do to make it input to the search box below it.

[url]http://gyazo.com/a155682d9f1f5fcbeb31ace29fccaf47[/url]

[url]http://gyazo.com/9643a8ca78ad4cb9ebdd8d545c41ccfe[/url]

Any further assistance would be greatly appreciated.

to post a comment
JavaScript

19 Comments(s)

Copy linkTweet thisAlerts:
@cootheadNov 28.2014 — Hi there Mattchuko,

[indent]

does this example help...
[color=navy]
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">

<title>keyboard</title>

<style media="screen">
body {
background-color:#f0f0f0;
}
#keyboard {
display:inline-block;
padding:10px 15px;
border:1px solid #009;
border-radius:10px;
background-color:#87cdf9;
text-align:center;
box-shadow:4px 4px 4px #999;
}
#keyboard div {
margin:5px 0;
}
#space {
width:184px;
}
#keyboard label {
margin-top:20px;
font-family:serif;
text-decoration:underline;
}
#keyboard input {
box-shadow:2px 2px 2px #666;
}
#keyboard input[type="text"] {
margin-top:20px;
border:1px solid #666;
border-radius:4px;
box-shadow:none;
}
</style>

<script>
(function() {
'use strict';
var i,c;
function init(){
i=document.getElementById('keyboard').getElementsByTagName('input');
for(c=0;c<i.length;c++) {
if(i[c].type==='button') {
i[c].addEventListener('onclick',makeClickHandler(c));
}
}

document.getElementById('clear').onclick=function() {
document.getElementById('text').value='';
}
}

function makeClickHandler(c) {
i[c].onclick=function() {
document.getElementById('text').value+=this.value.toLowerCase();
};
}

window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
})();
</script>

</head>
<body>

<div id="keyboard">

<div>
<input type="button" value="Q">
<input type="button" value="W">
<input type="button" value="E">
<input type="button" value="R">
<input type="button" value="T">
<input type="button" value="Y">
<input type="button" value="U">
<input type="button" value="I">
<input type="button" value="O">
<input type="button" value="P">
</div><div>
<input type="button" value="A">
<input type="button" value="S">
<input type="button" value="D">
<input type="button" value="F">
<input type="button" value="G">
<input type="button" value="H">
<input type="button" value="J">
<input type="button" value="K">
<input type="button" value="L">
</div><div>
<input type="button" value="Z">
<input type="button" value="X">
<input type="button" value="C">
<input type="button" value="V">
<input type="button" value="B">
<input type="button" value="N">
<input type="button" value="M">
</div><div>
<input id="space" type="button" value=" ">
<input id="clear" type="reset" value="clear">
</div><div>
<label>Track Search</label> - <input id="text" type="text" readonly="readonly">
</div>

</div><!-- end #keyboard -->

</body>
</html>[/color]

[/indent]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@HemanthmalliDec 03.2014 — I want to know the requirement that is in the second link if the users press the buttons in the keyboard means the search bar should work or else the required page should be open.
Copy linkTweet thisAlerts:
@MattchukoauthorDec 09.2014 — Hey there, thanks for the assistance with the keyboard, and it does work. However I do not understand what is making it work. We've only really done simple Javascript functions and not this type of thing, if you could provide a brief explanation of how this particular function works in comparison with a 'function (parameter,parameter){}' function I'd very much appreciate it, also, would it be possible to add a backspace key onto it?
Copy linkTweet thisAlerts:
@cootheadDec 09.2014 — Hi there Mattchuko,

[indent]

does this help in any way...
[color=navy]
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">

<title>keyboard</title>

<style media="screen">
body {
background-color:#f0f0f0;
}
#keyboard {
display:inline-block;
padding:10px 15px;
border:1px solid #009;
border-radius:10px;
background-color:#87cdf9;
text-align:center;
box-shadow:4px 4px 4px #999;
}
#keyboard div {
margin:5px 0;
}
#space {
width:184px;
}
#keyboard label {
margin-top:20px;
font-family:serif;
text-decoration:underline;
}
#keyboard input {
box-shadow:2px 2px 2px #666;
}
#keyboard input[type="text"] {
margin-top:20px;
border:1px solid #666;
border-radius:4px;
box-shadow:none;
}
#keyboard #back {
font-weight:bold;
}
</style>

<script>
(function() {
'use strict';
var i,c;
function init(){
/* get all the input elements within the div whose id is "keyboard */
i=document.getElementById('keyboard').getElementsByTagName('input');
/* loop through all the elements */ <br/>
for(c=0;c&lt;i.length;c++) {
/* find all the the input type="button" elements */
if(i[c].type==='button') {
/* add an onclick handler to each of them and set the function to call */
i[c].addEventListener('onclick',makeClickHandler(c));
}
}

/* this is the type="reset" input */
document.getElementById('clear').onclick=function() {
/* remove all the characters from the input type="text" element */
document.getElementById('text').value='';
}
}

function makeClickHandler(c) {
i[c].onclick=function() {
/* find the non-text button which has an id */
if(i[c].id==='back') {
/* remove last character from the input the type="text" element using regular expression */
document.getElementById('text').value=
document.getElementById('text').value.replace(/.$/,'');
}
/* find the text buttons */
else {
/* add characters to the input type="text" element */
document.getElementById('text').value+=this.value.toLowerCase();
}
};
}

window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
})();
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;div id="keyboard"&gt;

&lt;div&gt;
&lt;input type="button" value="Q"&gt;
&lt;input type="button" value="W"&gt;
&lt;input type="button" value="E"&gt;
&lt;input type="button" value="R"&gt;
&lt;input type="button" value="T"&gt;
&lt;input type="button" value="Y"&gt;
&lt;input type="button" value="U"&gt;
&lt;input type="button" value="I"&gt;
&lt;input type="button" value="O"&gt;
&lt;input type="button" value="P"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;input type="button" value="A"&gt;
&lt;input type="button" value="S"&gt;
&lt;input type="button" value="D"&gt;
&lt;input type="button" value="F"&gt;
&lt;input type="button" value="G"&gt;
&lt;input type="button" value="H"&gt;
&lt;input type="button" value="J"&gt;
&lt;input type="button" value="K"&gt;
&lt;input type="button" value="L"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;input type="button" value="Z"&gt;
&lt;input type="button" value="X"&gt;
&lt;input type="button" value="C"&gt;
&lt;input type="button" value="V"&gt;
&lt;input type="button" value="B"&gt;
&lt;input type="button" value="N"&gt;
&lt;input type="button" value="M"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;input id="back" type="button" value="&amp;#8592;"&gt;
&lt;input id="space" type="button" value=" "&gt;
&lt;input id="clear" type="reset" value="clear"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;label&gt;Track Search&lt;/label&gt; - &lt;input id="text" type="text" readonly="readonly"&gt;
&lt;/div&gt;

&lt;/div&gt;&lt;!-- end #keyboard --&gt;

&lt;/body&gt;
&lt;/html&gt;[/color]


I have also coded the backspace button. ?

[/indent]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@MattchukoauthorDec 09.2014 — Thank you very much, that's a great help.
Copy linkTweet thisAlerts:
@cootheadDec 09.2014 — [indent]

No problem, you're very welcome. ?

[/indent]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@sakthivel_mMar 12.2017 — HI,

I have multiple text box in my page by using this code i am able to get only for 1 text box the remaining text boxes keyboard is not working please give me suggestion
Copy linkTweet thisAlerts:
@jedaisoulMar 12.2017 — Thread moved from HTML forum to JavaScript.
Copy linkTweet thisAlerts:
@JMRKERMar 13.2017 — HI,

I have multiple text box in my page by using this code i am able to get only for 1 text box the remaining text boxes keyboard is not working please give me suggestion[/QUOTE]


Show your set-up code.
Copy linkTweet thisAlerts:
@i4imteyazJun 07.2017 — Hi Coothead,

i want to hide entire keyboard after 5 second (setTimeout()) if user not pressing any key, please share the code.

I will be very thankfull.
Copy linkTweet thisAlerts:
@cootheadJun 07.2017 — Hi there i4imteyaz,

[indent]

and a warm welcome to these forums. ?

Does this help...

[color=navy]
&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;

&lt;meta charset="utf-8"&gt;
&lt;meta name="viewport" content="width=device-width,height=device-height,initial-scale=1"&gt;

&lt;title&gt;keyboard&lt;/title&gt;

&lt;style media="screen"&gt;
body {
background-color: #f0f0f0;
font: 1em/1.62em verdana, arial, helvetica, sans-serif;
}
#keyboard {
padding: 0.75em 1.5em;
border: 0.062em solid #069;
border-radius: 0.75em;
background-color: #87cdf9;
background-image: linear-gradient( to bottom, #87cdf9, #549ac6);
box-shadow: 0.25em 0.25em 0.25em #999;
text-align: center;
}
#keyboard div {
margin: 0.4em 0;
}
#space {
width: 14em;
}
#keyboard label {
margin-top: 1.25em;
text-decoration: underline;
}
#keyboard input {
box-shadow: 0.15em 0.15em 0.15em #666;
}
#keyboard input[type="text"] {
margin-top: 1.25em;
border: 0.062em solid #666;
border-radius: 0.25em;
box-shadow: none;
}
#keyboard #back {
font-weight: bold;
}
.show {
display: inline-block;
}
.hide {
display: none;
}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;div id="keyboard" class="show"&gt;

&lt;div&gt;
&lt;input type="button" value="Q"&gt;
&lt;input type="button" value="W"&gt;
&lt;input type="button" value="E"&gt;
&lt;input type="button" value="R"&gt;
&lt;input type="button" value="T"&gt;
&lt;input type="button" value="Y"&gt;
&lt;input type="button" value="U"&gt;
&lt;input type="button" value="I"&gt;
&lt;input type="button" value="O"&gt;
&lt;input type="button" value="P"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;input type="button" value="A"&gt;
&lt;input type="button" value="S"&gt;
&lt;input type="button" value="D"&gt;
&lt;input type="button" value="F"&gt;
&lt;input type="button" value="G"&gt;
&lt;input type="button" value="H"&gt;
&lt;input type="button" value="J"&gt;
&lt;input type="button" value="K"&gt;
&lt;input type="button" value="L"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;input type="button" value="Z"&gt;
&lt;input type="button" value="X"&gt;
&lt;input type="button" value="C"&gt;
&lt;input type="button" value="V"&gt;
&lt;input type="button" value="B"&gt;
&lt;input type="button" value="N"&gt;
&lt;input type="button" value="M"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;input id="back" type="button" value="&amp;#8592;"&gt;
&lt;input id="space" type="button" value=" "&gt;
&lt;input id="clear" type="reset" value="clear"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;label&gt;Track Search&lt;/label&gt; - &lt;input id="text" type="text" readonly="readonly"&gt;
&lt;/div&gt;

&lt;!-- #keyboard --&gt;&lt;/div&gt;

&lt;script&gt;
(function() {
'use strict';
var i, c, t, delay = 5000, kb = document.getElementById('keyboard');
/* get all the input elements within the div whose id is "keyboard */
i = kb.getElementsByTagName('input');
/* loop through all the elements */ <br/>
for(c = 0;c &lt; i.length; c++) {
/* find all the the input type="button" elements */
if(i[c].type === 'button') {
/* add an onclick handler to each of them and set the function to call */
i[c].addEventListener('onclick',makeClickHandler(c));
}
}

/* this is the type="reset" input */
document.getElementById('clear').addEventListener('click',
function() {
/* remove all the characters from the input type="text" element */
document.getElementById('text').value = '';
},false);

function makeClickHandler(c) {
i[c].onclick=function() {
/* find the non-text button which has an id */
if(i[c].id === 'back') {
/* remove last character from the input the type="text" element using regular expression */
document.getElementById('text').value =
document.getElementById('text').value.replace(/.$/,'');
}
/* find the text buttons */
else {
/* add characters to the input type="text" element */
document.getElementById('text').value+= this.value.toLowerCase();
}
};
}
document.onmousemove = resetTimer;
document.onkeypress = resetTimer;

function logout() {
kb.classList.remove('show');
kb.classList.add('hide');
}

function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, delay)
}
resetTimer();
})();
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;[/color]


[/indent]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@rootJun 08.2017 — Why is an onscreen keyboard needed?

If its to avoid key stroke capture, its not going to solve anything, all keyboard (including virtual keyboards) all dump their data in to the buffer that reads inputs as malware and key stroke recorders record.
Copy linkTweet thisAlerts:
@dhenningJun 09.2017 — I found your keyboard code and like it very much. I would like to be able check the users input against a value, like a password check and have the screen display correct nor not correct after selecting a Check your answer button. Can you give me the bit of code that will allow me to do that? Thanks in advance.. Di
Copy linkTweet thisAlerts:
@JMRKERJun 09.2017 — I found your keyboard code and like it very much. I would like to be able check the users input against a value, like a password check and have the screen display correct nor not correct after selecting a Check your answer button. Can you give me the bit of code that will allow me to do that? Thanks in advance.. Di[/QUOTE]

It would be better to start your own thread than continue a thread started in 2014.

You will get more response. Plus, you should make at attempt at coding it yourself first.
Copy linkTweet thisAlerts:
@rootJun 10.2017 — It would be better to start your own thread than continue a thread started in 2014.

You will get more response. Plus, you should make at attempt at coding it yourself first.[/QUOTE]


I have suggested (like in many other forums) threads over a set time, get automatically locked from further posts, most forums set a 60 day limit, that then stops people resurrecting anything that died a few months or older.
Copy linkTweet thisAlerts:
@JMRKERJun 10.2017 — 60, 90 or 180 doesn't really matter to me.

Just 3 years seems excessive and unproductive.

There is no reason that the original site cannot be referenced with a link without adding to it.
Copy linkTweet thisAlerts:
@rootJun 10.2017 — Exactly what I have said over the past several years.

If a new post is made in an old forum thread, the post should IMHO be directed to a new post of its own thread.

What I also see is allot of newbies joining and resurrecting old threads which are often post count bumping exercises.
Copy linkTweet thisAlerts:
@sys_kpApr 25.2018 — Is it also possible to add a button to go to the next input text type field or the previous input text type field?
Copy linkTweet thisAlerts:
@rootApr 25.2018 — {"locked":true}
×

Success!

Help @Mattchuko spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...