problem with form field focus and determining the field name

admin

Administrator
Staff member
Hello All,

I have a form that will have 30 or so form buttons that represent the alphabet, spacebar and backspace. Just like a keyboard. I also will have around the same number of text fields. My problem is determining which text field I should be deleting from. If I only have one text field it works like a charm, more than that and it pukes.

Here is my code. Thanks in advance.

<script language="JavaScript">
function _setVar(fld) {
fldObj = "document.form2." + fld;
fldObjB = fld;
}
function keyPressed (keyd) {
if(document.form2) {
document.form2.fldObjB.value += keyd;
return true;
}
}
function _delete() {
var fldObjB = fldObj.value;
newlength = (fldObjB.length-1);
fldObj.value='';
for (i=0;i<newlength;i+=1) fldObj.value+=fldObjB.charAt(i)
document.form2.fldObjB.focus();
}

</script>


<form action="bottom.cfm" method="post" name="form2" id="form2">
<input type="text" name="fname" onFocus="_setVar('fname')"><br><br>
<input type="text" name="fname2" onFocus="_setVar('fname2')"><br><br><br>
<input type="button" name="A" value=http://www.webdeveloper.com/forum/archive/index.php/"A" style="width: 60px; height: 60px;" onClick="keyPressed('A')">&nbsp;&nbsp;
<input type="button" name="B" value=http://www.webdeveloper.com/forum/archive/index.php/"B" style="width: 60px; height: 60px;" onClick="keyPressed('B')">&nbsp;&nbsp;
<input type="button" name="C" value=http://www.webdeveloper.com/forum/archive/index.php/"C" style="width: 60px; height: 60px;" onClick="keyPressed('C')">&nbsp;&nbsp;
<input type="button" name="D" value=http://www.webdeveloper.com/forum/archive/index.php/"D" style="width: 60px; height: 60px;" onClick="keyPressed('D')">&nbsp;&nbsp;
<input type="button" name="E" value=http://www.webdeveloper.com/forum/archive/index.php/"E" style="width: 60px; height: 60px;" onClick="keyPressed('E')">&nbsp;&nbsp;
<input type="button" name="F" value=http://www.webdeveloper.com/forum/archive/index.php/"F" style="width: 60px; height: 60px;" onClick="keyPressed('F')">&nbsp;&nbsp;<br><br>
<input type="button" name="space" value=http://www.webdeveloper.com/forum/archive/index.php/"Space Bar" onClick="keyPressed(' ')">&nbsp;&nbsp;<input type="button" name="backspace" value=http://www.webdeveloper.com/forum/archive/index.php/"Backspace" onClick="_delete()">
</form>
 
Back
Top