Click to See Complete Forum and Search --> : problem with form field focus and determining the field name


ddevitt
04-11-2003, 11:02 AM
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="A" style="width: 60px; height: 60px;" onClick="keyPressed('A')">&nbsp;&nbsp;
<input type="button" name="B" value="B" style="width: 60px; height: 60px;" onClick="keyPressed('B')">&nbsp;&nbsp;
<input type="button" name="C" value="C" style="width: 60px; height: 60px;" onClick="keyPressed('C')">&nbsp;&nbsp;
<input type="button" name="D" value="D" style="width: 60px; height: 60px;" onClick="keyPressed('D')">&nbsp;&nbsp;
<input type="button" name="E" value="E" style="width: 60px; height: 60px;" onClick="keyPressed('E')">&nbsp;&nbsp;
<input type="button" name="F" value="F" style="width: 60px; height: 60px;" onClick="keyPressed('F')">&nbsp;&nbsp;<br><br>
<input type="button" name="space" value="Space Bar" onClick="keyPressed(' ')">&nbsp;&nbsp;<input type="button" name="backspace" value="Backspace" onClick="_delete()">
</form>

khalidali63
04-11-2003, 11:24 AM
:-)
Care to re describe your question please?

Khalid

ddevitt
04-11-2003, 11:36 AM
Here goes..

I have the following text fields:
1 for Name
1 for Address
1 for City
1 for State
etc...

This is a touchscreen application so there is no keyboard and mouse. So I built a form that will have 30 or so input buttons that represent the keyboard, spacebar and backspace. Now, if I type my name, address and am in the city text field and I misspell it I want to backspace to correct it. I've figured it out when I only have one text field (by hard coding the field name in my _delete function). If I have more than one text field it doesn't work. I'm trying to dynamically tell the function what field I'm in.

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="A" style="width: 60px; height: 60px;" onClick="keyPressed('A')">
<input type="button" name="B" value="B" style="width: 60px; height: 60px;" onClick="keyPressed('B')">
<input type="button" name="C" value="C" style="width: 60px; height: 60px;" onClick="keyPressed('C')">
<input type="button" name="D" value="D" style="width: 60px; height: 60px;" onClick="keyPressed('D')">
<input type="button" name="E" value="E" style="width: 60px; height: 60px;" onClick="keyPressed('E')">
<input type="button" name="F" value="F" style="width: 60px; height: 60px;" onClick="keyPressed('F')"> <br><br>
<input type="button" name="space" value="Space Bar" onClick="keyPressed(' ')"> <input type="button" name="backspace" value="Backspace" onClick="_delete()">
</form>

khalidali63
04-11-2003, 11:49 AM
in all of the text fields try something like this.

declare a global variable say name it

var currentField;

then in every text field in the onfocus = "currentField = this"

and when u click on backspace currentField.value.length = (parseInt(currentField.value.length)-1);

I have not tested it,but it sure seem like work..

Cheers

Khalid

ddevitt
04-11-2003, 01:30 PM
Khalid,

That didn't work.

khalidali63
04-11-2003, 02:21 PM
My guess is that your implementation of the suggestion is wrong..

:D

Let me try it..now

Cheers

Khalid

khalidali63
04-11-2003, 02:33 PM
Told ya, :p

Here you go.

http://68.145.35.86/temp/FormProblem-ddevitt.html

Cheers

Khalid

ddevitt
04-11-2003, 02:42 PM
that did it!!!! Thanks a bunch