Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Jan 2002
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HiHow to set focus to form

    Hi

    I have a web page where I obtain some simple text by a web page by a form eg

    <form method=post action="default.asp">
    <table border=0 align=center width="70%">
    <tr>
    <td>

    <input type=text name=search size=30>


    Is there a way that a run time I can set the focus of the cursor to the form when the page is loaded?

    Thanks

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: HiHow to set focus to form

    Try this:
    (note - extra space added to tags to prevent the Lounge confusing it with a real tag)

    < body onload="document.form1.search.focus()" >

    < form action="default.asp" name="form1" method="post" >

    < input type="text" name="search" >

    Hope this helps!

  3. #3
    Lounger
    Join Date
    Jan 2002
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to set focus to form

    Thanks

    This worked.

    Regards

  4. #4
    Lounger
    Join Date
    Jan 2002
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to set focus to form

    Now that I have the cursor in the form text input box, is it possible to have the text that was input by the page "selected". The code which writes the to the text box is

    < input type=text name=search size=30 value="<%response.write request.form("search")%>" >
    < /td >
    < /tr >
    < tr >
    < td><input type=submit name=submit value=Again >


    Thanks again

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: How to set focus to form

    Internet Explorer has some extensions to the DOM that let you work with contents of a control as a TextRange, but this is not cross-browser. If you'd like to see an example, take a look at the code behind the 1-Click TagPanel (the link above the message area when you are composing a post) that can insert markup at the current insertion point position (or add bold on and bold off tags around selected text).

Posting Permissions

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