Results 1 to 6 of 6

Thread: Setting the focus on a DHTML page.

  1. #1

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Question Setting the focus on a DHTML page.

    How do I set the focus on a particular textarea control when my page loads into the browser ?

    At the moment when it loads nothing seems to have the focus, and I have to click into the box manually !

    Any response much appreciated.

    Thanx.

  2. #2
    sarun
    Guest
    One way of doing this:

    In the window onload event place this:

    Formname.Controlname.focus();


    I am not sure if this is the right way but it works.

  3. #3

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    I gave it a go, but it fell over with an 'Object Required' error.

    This was my code :

    ********************************************
    Private Sub BaseWindow_onload()
    DHTMLPage1.txtSCRDescription.focus

    End Sub
    ********************************************

    Any more ideas ?

  4. #4
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Is that (DHTMLPage1) the NAME of your form? As in, the name attribute inthe FORM tag. If not, it's not finding the text control. Also make sure you use the name attribute (I use both name and id and set them to the same thing) in any form data tags.

    You didn't post all the code so I couldn't tell whether this is the problem or not.. but it sure sounds like it.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  5. #5

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    !

    Yes, DHTMLPage1 is the name of my form.

    It appears under the 'name' and the 'id' already.

    But thanks for responding. Any more ideas ?

    The control I am trying to set the focus on is a textarea control.

    The form has a 'RESET' button which clears all fields and sets the focus to this control. This works fine. I just can't get it to set the focus when the form is loaded !!!!

  6. #6
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Ok... your doing something wrong then.. cuz this works every time:


    Code:
    <HTML>
    <HEAD>
    <SCRIPT language=javascript>
    function window_onload()
    {
    	MyForm.MyText.focus();
    }
    </SCRIPT>
    </HEAD>
    <BODY onload="window_onload()" link="red">
    <form name="MyForm" id="MyForm">
    <input name="MyText" id="MyText" type="textarea">
    </FORM>
    </BODY>
    </HTML>
    Remember that javascript is case sensitive so you have to type the names there exactly the same as in your tags
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

Posting Permissions

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



Click Here to Expand Forum to Full Width