Click to See Complete Forum and Search --> : How to Maintain the focus in JavaScript?


adusumalli
June 12th, 2008, 01:34 PM
Hi ,

In my screen i have a table. Table has 8 columns and several rows. In 8 columns, one of the column value has link is there for open the popup. when i am going to select the link to open the popup the entire row will be heighlighted ( means it shows in gray color). After updates done in popup, popup page will close and comeback to the previous page i.e in table page and that table page will be reloaded and updates will be showing. but the problem is prevoius focus (i.e previous heighlighted color gray) is not maintaining. So, what is the problem? can any body give the solution?


Thanks in advance.....

PeejAvery
June 12th, 2008, 02:11 PM
Since it is gray highlighting, that means that the focus has not changed within the window, but that the window itself has lost focus.

Use the opened window to tell the parent to focus.

adusumalli
June 12th, 2008, 02:42 PM
how to tell the parent window to maintain the focus?
Can u give sample code. or an example pls. it's urgent.

PeejAvery
June 12th, 2008, 02:56 PM
Are you unable to search things out? Remember that Google is a great resource and will return plenty for JavaScript focus.

From the opened window to the parent.
opener.focus();
From the parent window itself...
document.window.focus();

adusumalli
June 12th, 2008, 03:20 PM
Hey thanks for reply. where exactly place this code? I am new to JavaScript.

thanks

PeejAvery
June 12th, 2008, 03:30 PM
The first example would go wherever the code that closes the window is. The second would go wherever the code that opens the window is.

adusumalli
June 12th, 2008, 03:35 PM
I am giving my code like this way:

In my main.jsp page, the Javascript part is:

function refreshAndInit()
{
if ( $('divTaskName_0')!=null )
{
$('newtaskinline').style.position = "absolute";
$('newtaskinline').style.top = getAbsElementYById( 'divTaskName_0' );
$('newtaskinline').style.left = getAbsElementXById( 'divTaskName_0' ) - 4;
$('newtaskinline').value = '';
// $('newtaskinline').focus();
// ebjs_debug( ' ' + getAbsElementYById( 'divTaskName_0' ) + ' ' + getAbsElementXById( 'divTaskName_0' ) );
}
fcCalRefreshInProgress = 0;
_gTextMode = 1;
_gTextMode2TaskId = 0;

}
function newTaskInlineUnfocusHandler( in_responseText, in_param )
{
$('newtaskinline').value = '';
$('mainTaskDiv').innerHTML = in_responseText;

refreshAndInit();
}

SimpleAJAXCall ( 'xhpPrjCTask.jsp'+genappend_submiturl+'&prjid=<%=id%>&ptid='+parentTaskId+'&tid='+tskid+'&movetoid='+movetoid+'&act=MOVE_UPDOWN&order='+order, newTaskInlineUnfocusHandler, 'POST', '' ); (through ajax we r calling xhpPrjCTask.jsp, in this jsp we have the table)

var _gOldHightlightTaskId = -1;
function changeContext( taskId ) (this method is calling from xhpPrjCTask.jsp)
{
if ( _gOldHightlightTaskId > 0 && $('TD_TASK_'+_gOldHightlightTaskId) != null )
{
$( 'TR_LINE_'+_gOldHightlightTaskId ).bgColor='FFFFFF';
}

_gOldHightlightTaskId = taskId;
_gTaskId = taskId;
if ( _gOldHightlightTaskId > 0 && $('TD_TASK_'+_gOldHightlightTaskId) != null )
{
$( 'TR_LINE_'+_gOldHightlightTaskId ).bgColor='CCCCCC';
document.window.focus(); ( your code)
}
refreshDetailTab();
}

--------------
In xhpPrjCTask.jsp ( This is table JSP. which is calling from above JSP page and above JSP and this JSP are placed in same screen)

<tr id="TR_LINE_<%=t.getID()%>" bgcolor="#FFFFFF" onClick="changeContext(<%=t.getID()%>);" > (this is the table starting row in this row we can see the "changeContext()" , when i going to select the link in the table, changeContext() will call and selected row should display as in Gray color)
--------------
-------- ( these are getting data for remaining columns)
----------
<td class=verySmall valign=middle nowrap name="taskname" id='TD_TASK_<%=t.getID()%>'><div id='divTaskName_<%=t.getID()%>:divParentTask_<%=t.getParentTaskId()%>' onClick="MM_openBrWindow('ozPrjTaskDtl.jsp?id=<%=t.getID()%> ','prjEdit','width=780,height=580');" oncontextmenu="return contextMenuCursor( event, 'PRJEDIT', '<%=t.getID()%>', '-1' );" class=dragclass><a href="#" ><%=AhsStringUtil.limitLength(t.getName(),60)%></a></div></td> (this is the link for popup window i.e ozPrjTaskDtl.jsp is the popup window in this page we did updates and it comeback to main.jsp page)

--------------
-------- ( these are getting data for remaining columns)
----------
</tr> (table end here)

thanks.......

PeejAvery
June 12th, 2008, 03:39 PM
Please use [code] (http://www.codeguru.com/forum/misc.php?do=bbcode#code) tags when posting.

That code is not relevant to any popup windows. Either way, there is a lot of code, both server-side and client-side, in your project. I do not have the time to just go through and edit it for you.

The forums exist to help, not do do everything for others. We have helped...now its your turn to try.

adusumalli
June 12th, 2008, 04:02 PM
Hey I used your code like this way, but still i am not getting the focus.

this is calling Popup window

<td class=verySmall valign=middle nowrap name="taskname" id='TD_TASK_<%=t.getID()%>'><div id='divTaskName_<%=t.getID()%>:divParentTask_<%=t.getParentTaskId()%>' onClick="MM_openBrWindow('ozPrjTaskDtl.jsp?id=<%=t.getID()%> ','prjEdit','width=780,height=580', 'document.window.focus();');" oncontextmenu="return contextMenuCursor( event, 'PRJEDIT', '<%=t.getID()%>', '-1' );" class=dragclass><a href="#" ><%=AhsStringUtil.limitLength(t.getName(),60)%></a></div></td>


and In the popup window i used like this way:

<!-- Save and Close -->
<a href="#" class=verySmallGrey2NL onClick="document.updateTask.elements['ahsFormAction'].value='updateNClose';document.updateTask.submit();try { opener.focus(); } catch (Exception) {};"> <%=_prompt.get("save_and_close_window")%> <img src="graphics/arrow_btn.gif" align=absmiddle border=0></a> &nbsp; | &nbsp;


please see this , I think i am very close to solve the problem.

thanks...

PeejAvery
June 12th, 2008, 05:13 PM
Don't use both. I was just giving you two possible implementations. Change the code in the popup to the following.

...onClick="opener.focus();document.updateTask.elements['ahsFormAction'].value='updateNClose';document.updateTask.submit();"...

adusumalli
June 13th, 2008, 03:40 PM
Hey ,

thanks for your immediate reply. It's very usefull to me.