Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

focus() not working...

Status
Not open for further replies.

gabrielAllen

Programmer
Feb 14, 2001
19
0
0
US
I have a form (main) with a row of several fields. In the first field, an "onDblClick" opens a small window (child) with a list of values. When you double a value in the child window, it closes and populates the row in the main page.

Here is my problem, after I close the child window and it populates the row, I need the focus on the main to be in a specific field. How can I do this?

Thanks
Ken
 

You've said that "focus()" isn't working? Can you show the code that you have at the moment with the "focus()" call that you have?

The only restriction I know of WRT the focus() call is that in IE, some elements must have a tabindex set to allow the focus method to work on them. Try adding a tabindex of 1 to the elements taht you want focussed:

Code:
<el tabindex="1">...</el>

Hope this helps,
Dan
 
This line might help you out. Put it before your line that closes the popup window. tb3 should be changed to the text box name that you want to focus on, frm1 should change to your form name.

Code:
opener.frm1.tb3.focus();

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
:) Thanks! I realized it was time for a change.

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Thanks for the help, but neither of these work... Here is a bit more infor.

The form uses a button, "Add", or a "onKeyDown" (tab) on the last field of the current row to create a new row. This field is created dynamically. Here is a portion of the function that the "Add" and tab uses to create the new row:

Code:
function addRows()
{
R=tblAllocate.insertRow(-1);
C=R.insertCell(-1);   
C.innerHTML="<td width='9%' ><div align='center' ><input type = 'text' name='empNo' id='empNo"+(R.rowIndex-2)+"' size='6'  onDblClick=\"strDblStatus='DBCLICKED';popupAllocateEmployeeTime(this);\" onChange=\"strCtlName=this.id;setRtnIDs('ALLOCATERELIEFTIMEEMPLOYEE');if(setCriteriaforAllocaterReliefTimeEmployee(this.value)){checkValue('ALLOCATERELIEFTIMEEMPLOYEE',this.value)}\" onFocus=\"setCheckControl(this,'ALLOCATERELIEFTIMEEMPLOYEE');\" onBlur=\"checkError(this)\" onkeypress=\"return ('0123456789'+(this.value.indexOf('.')>-1?'':'.')).indexOf(String.fromCharCode(event.keyCode))>-1\"><input type = 'hidden' name='empId' id='empId"+(R.rowIndex-2)+"'\></div></td>";
...
... 
	document.getElementById("empNo"+(R.rowIndex-2)).focus();
}

Lets start here... Here is another problem that may solve the other. Notice the last line where I call the focus() to put focus on "empNo". The focus moves the the proper place when I use the "Add" button, but when I use the "onKeyDown" event which calls the same function, AddRows - listed above, it doesn't work.

Something is happening differently in the "Add" that is not happening in the "onKeyDown" event. Any clues?
 
Well, both use the addRow function above. Here is what I use on the "onKeyDown":
Code:
...
C=R.insertCell(-1);
C.innerHTML="<td width='9%'><div align='center'><input type = 'text' id='overMins"+(R.rowIndex-2)+"' name='overMins' size='2' maxlength='2' onKeyDown='checkIt(event)'></div></td>";

The "onKeyDown" calls "checkIt()" which checks for a "tab" and then calls the "addRows".
Code:
function checkIt(e)   
{   
event.keyCode:e.keyCode;   
if (9==event.keyCode){
addRows();
}  
}

Here is the html for the ADD button:
Code:
<td width="12%" align="center" valign="bottom"><img src='../../pictures/AddUp.gif' name='add' width=80 height=23 onClick='addRows()' onMouseOver= MM_changeProp('add','','src','../../pictures/AddOut.gif','IMG') onMouseOut=MM_changeProp('add','','src','../../pictures/AddUp.gif','IMG') style=cursor:hand >
</td>

 
Try adding "return(false);" to the end of your "checkIt" function.

It may well be that the tab key code is running, but then the browser is actioning the tab and moving the focus to the next field.

Hope this helps,
Dan
 
Hey! the "return(false);" stops the function from working completely. :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top