Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2008
    Location
    Falls Chuch, VA
    Posts
    30
    Thanks
    0
    Thanked 1 Time in 1 Post

    how to put focus on onClick of a button

    Hello.

    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.

    Code:
     <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.setDbInfo( "SLS_ADDRESS a", "a.ACTIVE_STATUS='Y' AND a.OWNER_TABLE_NAME='SLS_CUSTOMER' AND a.OWNER_TABLE_ID="+id );
      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();">
        <BR>
        <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="">
      </form>
    Thanks in Advance

  • #2
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    try an onload=document.TblActionForm1.btnUpdate.focus();
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #3
    New Coder
    Join Date
    Jul 2008
    Location
    Falls Chuch, VA
    Posts
    30
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi Hinch. I tried the onload but its not working. Do u have any other ideas ?

  • #4
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    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
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #5
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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:
    Code:
    window.onload=function(){document.TblActionForm1.btnUpdate.focus();}
    Hope it helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •