I have several buttons made to reflect an onscreen keyboard. I also have several input forms above them. I want the user to click on any of the buttons and have them fill in the forms with out the keyboard. Only using the mouse or a touch screen. Is this possible with javascript.
Announcement
Collapse
No announcement yet.
On screen buttons, acting like a keyboard
Collapse
X
-
this ok?
here's a rough idea. it allows the user to press the buttons and their value will be added to the current text box. if they click another text box, that will be set as 'vCurrent' and will be typed into. Use your existing buttons, just stick onclick="fType(insert key here)" into their tags. also use your existing text boxes, just make sure you give them names of field1, field2 etc. or the selection thing won't work.
you will need a backspace button and it might be nice to be able to insert text partway through a field. i haven't done this cos i dont know exactly what you need.
Code:<HTML> <HEAD> <TITLE>typing thing</TITLE> <SCRIPT language=javascript> <!-- var vCurrent = 1 function fType(keyPressed){ //adds the value of the pressed button to the field. eval("document.frmStuff.txtField" + vCurrent + ".value += keyPressed") } //--> </SCRIPT> </HEAD> <BODY> <FORM name=frmStuff> <P><INPUT type=text name=txtField1 size=50 onclick="vCurrent = 1"></P> <P><INPUT type=text name=txtField2 size=50 onclick="vCurrent = 2"></P> <P><INPUT type=text name=txtField3 size=50 onclick="vCurrent = 3"></P> <P> <INPUT type=button name=btnKeyQ value="Q" onclick="fType('Q')"> <INPUT type=button name=btnKeyW value="W" onclick="fType('W')"> <INPUT type=button name=btnKeyE value="E" onclick="fType('E')"> <INPUT type=button name=btnKeyR value="R" onclick="fType('R')"> <INPUT type=button name=btnKeyT value="T" onclick="fType('T')"> <INPUT type=button name=btnKeyY value="Y" onclick="fType('Y')"> <!--etc.--> </P> </FORM> </BODY> </HTML>
EDIT: 14/07/02 11:19 AM BST: inserted single quotes into scriptLast edited by neil.c; Jul 14, 2002, 06:20 AM.neil.c
Comment
-
function backspace() {
document.theForm.theTextBox.value = document.theForm.theTextBox.value.slice(0, document.theForm.theTextBox.value.length -2);
}
tab.where = 0;
function tab(posinega) {
document.theForm.elements[tab.where + posinega].focus();
}
tab is written the way it is, so that you can make it tab forwards or backwards.
tab(1); // tabs to the next space;
tab(-1); // tabs backwards;
keep in mind that if the person has a mouse, they really don't need the tab.
also, the backspace function is sad, and there's nothing that can be done about it, because there's no good cross browser way to find out where the cursor is in a string. also, that means that ability to insert text, copy or cut text, etc, will all also be either really really hard to write, or simply impossible. i'm not sure which.
Comment
-
At this link is where it is at. I cannot get the tab to work properly
<HTML>
<HEAD>
<TITLE>typing thing</TITLE>
<SCRIPT language=javascript>
<!--
var vCurrent = 1
function fType(keyPressed){ //adds the value of the pressed button to the field.
eval("document.frmStuff.txtField" + vCurrent + ".value += keyPressed")
}
function backspace() {
document.frmStuff.theTextBox.value = document.frmStuff.theTextBox.value.slice(0, document.frmStuff.theTextBox.value.length -2);
}
tab.where = 0;
function tab(posinega) {
document.frmStuff.elements[tab.where + posinega].focus();
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM name=frmStuff>
<P><INPUT type=text name=txtField1 size=50 onclick="vCurrent=1"></P>
<P><INPUT type=text name=txtField2 size=50 onclick="vCurrent=2"></P>
<P><INPUT type=text name=txtField3 size=50 onclick="vCurrent=3"></P>
<P>
<INPUT type=button name=btnKeyQ value="Q" onclick="fType('Q')">
<INPUT type=button name=btnKeyW value="W" onclick="fType('W')">
<INPUT type=button name=btnKeyE value="E" onclick="fType('E')">
<INPUT type=button name=btnKeyR value="R" onclick="fType('R')">
<INPUT type=button name=btnKeyT value="T" onclick="fType('T')">
<INPUT type=button name=btnKeyY value="Y" onclick="fType('Y')"><BR><BR>
<INPUT type=button name=btnKeyTab value="Tab" onclick="tab(1)">
<!--etc.-->
</P>
</FORM>
</BODY>
</HTML>If you don't do it this year, you will be one year older when you do. "Warren Miller"
Comment
-
made a typo when i wrote the function. this should work:
tab.where = 0;
function tab(posinega) {
document.frmStuff.elements[tab.where += posinega].focus();
}
Comment
-
wow, i'm out of it today or something.
try this:
tab.where = 0;
function tab(posinega) {
tab.where += posinega;
document.frmStuff.elements[tab.where].focus();
}
Comment
Comment