Can focus be set to a form's input text box upon loading of the page?

Results 1 to 3 of 3

Thread: Can focus be set to a form's input text box upon loading of the page?

  1. #1
    Lori K. Guest

    Default Can focus be set to a form's input text box upon loading of the page?

    Can the focus be set to a form&#039s input text box so the user is already "sitting" on the appropriate place to begin input of data? (e.g. the "Enter your login" input field).<BR><BR>I&#039m used to SetFocus in VB, but I&#039m new to ASP. I&#039ve done some reading on object.focus from the microsoft site, but I can&#039t figure out how to use this in conjuntion with &#060;form> and &#060;input>.<BR>I did make object.focus work as follows...<BR>&#060;body onload="test.focus" language="vbscript"><BR>&#060;input name="test"><BR>but this does not work when &#060;input> is used within &#060;form>.<BR><BR>Any ideas? Thanks.

  2. #2
    Sam Otto Guest

    Default RE: Can focus be set to a form's input text box upon loading of the page?

    Here&#039s the Javascript to do it...<BR><BR>&#060;script language="javascript"><BR> function init()<BR> {<BR> f = document.forms[0];<BR> f.elements[0].focus(); // set focus to first element<BR> return true;<BR> }<BR>&#060;/script><BR><BR>&#060;body onLoad="init()><BR>&#060;/body>

  3. #3
    Lori K. Guest

    Default It works! Just one minor change...

    It seems to want &#060;body onLoad="init()"><BR><BR>Needs a closing quote.<BR><BR>Thanks SOOOO much. This is so cool.<BR><BR>Lori K.

Posting Permissions

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