Results 1 to 3 of 3

Thread: focus on text field w/o body using AJAX

  1. #1
    Join Date
    Aug 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default focus on text field w/o body using AJAX

    ****focus on text field when page loads using AJAX****

    Hello all,

    In our application we are using AJAX for our home page and all the related pages are included to it.

    Its working fine. But i am unable to do focus on the first text field in the included pages as we do for normal form using onLoad & document.formname.elementname.focus funtion in body tag.

    Here thre problem is- since it is included pages, we dont have body or form to set focus using above mentioned js function.

    Is there any solution for this?
    Could any one please tell me the solution for this problem as it is very important.

    Thanks in advance,
    Aug_09

  2. #2
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Please post a link to the page on your site that contains the problematic script so we can check it out.

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This requires a small transparent .gif image, or really any small image, as it will never be seen. Example code for a page with a form to be loaded via Ajax w/ it's first text field brought to focus:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <form action="#" name="test">
    <input type="text" name="text1"><br>
    <input type="text" name="text2"><br>
    <input type="submit" value="Go">
    </form>
    <img style="visibility:hidden;position:absolute;top:-1000px;" src="spacer.gif" 
    onload="setTimeout(function(){document.forms['test']['text1'].focus();},300);">
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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