View Full Version : how to put focus on onClick of a button

09-02-2008, 09:52 PM

I have a form which has a button named Update_primary. This button is at the bottom of my JSP. I have to scroll down to click on this on this button. When i click on this button it does 2 things.

1) It refreshes the whole page.

2) It is supposed to maintain the focus on the button. Here it is not maintaing the focus.

My Question is how can i maintain the focus on the button when clicked.

I am also sending the HTML form which has the button.

<form name="TblActionForm1" action="<%=page_url%>" method="post">
if ( _ahsPage.isPpolPage() )
out.println( "<table width=100% cellspacing=0 cellpadding=0 border=0>" );
out.println( "<tr><td align=right class=verySmall>" );
out.println( " <a href='#' class='ppolSmallLink' onclick=\"javascript:Toggle('quickCreateAddress');\">Create New Address <img src=\"graphics/arrow_btn.gif\" border=0></a>" );
out.println( "</td></tr>" );
out.println( "<tr><td height=3><img src=\"graphics/z0.gif\" height=3></td></tr>" );
out.println( "</table>" );

OzPromptSalesAddress _pAddr = new OzPromptSalesAddress(_ahsPage);
DpdUiTable.ColumnHeaderType[] hdrs = new DpdUiTable.ColumnHeaderType[4];
hdrs[0] = new DpdUiTable.ColumnHeaderType( _pAddr, "primary", "PRIMARY_FLAG", "PRIMARY_FLAG", false );
hdrs[1] = new DpdUiTable.ColumnHeaderType( _pAddr, "type", "ADDRESS_TYPE", "ADDRESS_TYPE", true );
hdrs[2] = new DpdUiTable.ColumnHeaderType( _pAddr, "address", "ADDR_LINE1", "ADDRESS", true );
hdrs[3] = new DpdUiTable.ColumnHeaderType( _pAddr, "map", "PRIMARY_FLAG", "MAPQUEST", false );
DpdUiTable uit = new DpdUiTable( "addrs", hdrs );
uit.setPkInfo( "a.ADDRESS_ID", "org.oz.sales.customer.Address" );
uit.setSortColumn( 0, true );
uit.processRequest( _ahsPage, request );
<%= uit.render(_ahsPage) %>
if ( cust.accessControlCanUpdate(_ahsPage) )
<input class="smallButton" type=button name=btnUpdate value="<%=_pAddr.get("update_primary")%>" onclick="Javascript:document.TblActionForm1.ahsFormAction1.value='UpdateIdentifying'; document.TblActionForm1.submit();">
<span class=verySmall><img src="graphics/ozicontip2.gif" align=absmiddle> <%=_pAddr.get("expl_address")%></span>
<input type=hidden name=id value="<%=id%>">
<input type=hidden name=ahsFormAction1 value="">

Thanks in Advance

09-02-2008, 10:06 PM
try an onload=document.TblActionForm1.btnUpdate.focus();

09-02-2008, 10:45 PM
Hi Hinch. I tried the onload but its not working. Do u have any other ideas ?

09-02-2008, 10:53 PM
not really did you put the onload in the <body> ?

i'm affraid my js isn't that amasing though so if that doesn't work you'll have to dig one of the guru's up they'll no doubt come up with something fantastical for you :)

09-03-2008, 06:01 AM
When the update_primary button is pressed, it submits the form which refreshes the page altogether. Try to set the focus every load of the page instead:


Hope it helps.