Results 1 to 4 of 4

Thread: Focus is not not working in FF

  1. #1
    Join Date
    Jul 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Focus is not not working in FF

    hi,

    Below is the code which is working for IE but not working for FF...
    can any bady tel me how to set focus for FF... as shown below. The below there is to focus() where 'all' is wroking for IE and FORMS[] is not working for FF..


    Code:
    <html>
    <head>
    <script language="JavaScript">
     
     function checkme(strVal){
     var id=strVal;
                alert(id);
         //document.all[strVal].focus();---->(IE) FOR IE it is working but not working for mozilla firefox
         document.forms[strVal].focus(); //(FIREFOX)
     }
    </script>
    </head>
    <body>
    <form>
    NAME..<input type="text" name="empName" size="5" maxlength="4" onChange="checkme(this.value)"/><br>
    ID....<input type="text" name="id" value=""/><br>
    DEPT..<input type="text" name="dept" value=""/><br>
    </form>
    </body>
    </html>
    thx,
    Ajay.

  2. #2
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Code:
    document.getElementById(strVal).focus();

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Your HTML is invalid (http://validator.w3.org/). It should validate as HTML 4.01 Strict for most applications.

    DimX, your code will not work with that markup. The element does not have an ID, so getElementById() should not find it (although it will in IE, another bug).

    msg2ajay, the easiest way to do it is to use DimX' code, and give your element an ID. With your existing excuse for markup, you can do:
    Code:
    document.forms[0].elements[strVal].focus();
    ... but since your document is so invalid I wouldn't advise it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default focus to the control.

    The control “empName” has a event “onChange="checkme(this.value)” which passes value of the object. Whereas “focus()” needs object to be focused.
    So to focus any object you need to pass it’s object as “onChange="checkme(this);

    May be it will help to you.




    <html>
    <head>
    <script language="JavaScript">

    function checkme(strVal){
    var id=strVal.id;
    alert(id);
    //document.all[strVal].focus();---->(IE) FOR IE it is working but not working for mozilla firefox
    document.forms[strVal].focus(); //(FIREFOX)
    }
    </script>
    </head>
    <body>
    <form>
    NAME..<input type="text" name="empName" size="5" maxlength="4" onChange="checkme(this)"/><br>
    ID....<input type="text" name="id" value=""/><br>
    DEPT..<input type="text" name="dept" value=""/><br>
    </form>
    </body>
    </html>

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
  •