SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    focus-sing an input field

    I have an login in script (php) and would like that if that login page (html) is displayed that the cursor is already in the first input field.
    IMHO that can be done with js but, stupid me, somehow it seems i can't get it to work.
    Any hints?
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    try this

    Code:
    <HEAD>
    
    <SCRIPT LANGUAGE="JavaScript">
    
    <!-- Begin
    function toForm() {
    document.form.field1.focus();
    // Replace field1 in the script with the field name of which you want to place the focus.
    }
    //  End -->
    </script>
    
    </HEAD>
    
    <!-- Insert the onLoad event handler into your BODY tag  -->
    
    <BODY onLoad="toForm()">
    
    <FORM  NAME="form" METHOD="POST" ACTION="#">
    <SELECT NAME="field1" SIZE="1">
    <OPTION VALUE="one">Field 1
    <OPTION VALUE="two">also field1
    </SELECT>
    <BR>
    <INPUT TYPE="TEXT" NAME="field2" SIZE="10"> Field 2<BR>
    <INPUT TYPE="TEXT" NAME="field3" SIZE="10"> Field 3<BR>
    <BR>
    <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Submit">  
    <INPUT TYPE="RESET" onclick="toForm();">
    </FORM>
    I found the script here

  3. #3
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also this would work:
    BODY onLoad="document.form_name.field_name.focus()">

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Or this:
    Code:
    window.onload = function() 
    {
      document.form_name.field_name.focus();
    }
    But now we're just arguing semantics and preference .

  5. #5
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Leon4003
    try this [...]
    thank you, that's exactly what i was looking for
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.


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
  •