focus is working in IE but not working in FF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • msg2ajay
    New Member
    • Jun 2007
    • 17

    focus is working in IE but not working in FF

    hi,
    i have tried like this ... but i am not able to continue with this code... any bady hav idea on this???

    Code:
    <html>
    
    <head>
    <script language="JavaScript">
     
    function checkme(strVal){
    	
    			var id=strVal;
    		[B]---------->[/B]	[B]document.forms[0].+id+.focus();[/B]
    }
    </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>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    Try: [CODE=javascript]document.forms[0][id].focus();[/CODE]

    Comment

    • msg2ajay
      New Member
      • Jun 2007
      • 17

      #3
      focus is wroking in IE but 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>

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I've merged the threads - see my earlier solution. That should work in all browsers.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by msg2ajay
          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..
          document.all only works in IE and one or two browsers that added support for it. It is not standard. To access elements, you should give them an id and use document.getEle mentsById instead.

          Comment

          • msg2ajay
            New Member
            • Jun 2007
            • 17

            #6
            Originally posted by acoder
            document.all only works in IE and one or two browsers that added support for it. It is not standard. To access elements, you should give them an id and use document.getEle mentsById instead.
            hi,

            Clearly my code is like this.... is it possible like this or something like this

            <html>
            <head>
            <script language="JavaS cript">

            function checkme(strVal) {
            document.forms[strVal].focus(); //(FIREFOX)
            }
            </script>
            </head>
            <body>
            <form>
            NAME..<input type="text" name="empName" size="5" maxlength="4" onChange="check me(this.value)"/><br>
            ID....<input type="text" name="id" value=""/><br>
            DEPT..<input type="text" name="dept" value=""/><br>
            </form>
            </body>
            </html>

            thx & rgds,
            Ajay

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Change that to: [CODE=javascript]document.forms[0][strVal].focus();[/CODE]

              Comment

              Working...