SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function/focus problem

    i made an external javascript page that has a function that sets the focus to a text box of a form when i call it. i have many forms on manyf different pages so i did not want to have to keep typing the function out everytime, so this is what i did:

    created a function in focus.js:
    function focus(field) {
    document.forms[0]. + field + .focus();
    }
    where field would be the name of the textbox that i want to set the focus to.

    then i called the function using the onload function in the body tag:
    onLoad="focus('username')".

    for some reason thus does not work, any help would be greatly appreciated.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <body....onload="document.forms[0].username.focus()">
    ::: certified wild guess :::

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    function focus(field) {
    document.forms[0].elements[field].focus();
    }
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •