*
The moose likes HTML, CSS and JavaScript and the fly likes Passing data to specific textbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Passing data to specific textbox" Watch "Passing data to specific textbox" New topic
Author

Passing data to specific textbox

Ratan Pawar
Ranch Hand

Joined: Jan 18, 2008
Posts: 33
Hello,

i have a page having a two frame...
the upper main frame has a form page having 7 to 8 text boxes
and the bottom frame has keyboard.

i want to do following steps:

when i type from keyboard which is at bottom frame the input goes to the
text box of main frame were the cursor was placed.

it works successfully for only one text box which i get the text box by id for input.

But i want input goes to the text box having cursor position because the page from the main frame is changed.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Sounds like you need to figure out how to pass the id of the textbox to your function when a new textox is focused.

Play with this:
onfocus="alert(this.id);"

Eric
Ratan Pawar
Ranch Hand

Joined: Jan 18, 2008
Posts: 33
Sir, i read about onfocus by this we can get id or name of element.
but i want to use touchscreen.whatever i type it goes in the field which is active.(i am using firebox).
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
So you now can get the id. You store that in a variable. You refernce that variable in your bottom frame and set the "virtual keyboard" value into that textbox.

Without knowing how the keyboard is setting the value I can guess something like this:

Top Frame


Bottom Frame


Eric
Ratan Pawar
Ranch Hand

Joined: Jan 18, 2008
Posts: 33
Yes Sir,
i did it and it also working.
but sir is it possible,as i write a separate js file in which i find the element which has focus.
instead i give attribute onfocus to each element.
because sir there are 10 to 15 forms and each has 10 to 15 element.

i do it as:

function getElementWithFocus()
{
var f_ele = null;
for(var i=0;i<parent.mainFrame.document.forms.length;i++)
{
try
{
if ( parent.mainFrame.document.forms.elements[i].gotFocus )
{
alert( parent.mainFrame.document.forms.elements[i].name + ' has focus!');
f_ele = parent.mainFrame.document.forms.elements[i];
break;
}
}
catch (ex)
{
}
return f_ele;
}
}

but its not working or not showing any error.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
well there is no method/property called getFocus

On the window.onload of the for you can set the onfocus handlers on the elements.



Eric
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Passing data to specific textbox
 
Similar Threads
Set cursor without focus?
Keyboard Input
Updating Google Page search text box
Pop up box
Column Tabbing issue in DataTable