Focus and opera

Discussion in 'JavaScript' started by ahkip, Jul 7, 2006.

  1. #1
    I have a html form and want to set focus on a textarea. It work in all browser except opera. Anyone got some workaround?
     
    ahkip, Jul 7, 2006 IP
  2. danielbruzual

    danielbruzual Active Member

    Messages:
    906
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    70
    #2
    Works for me in Opera 8.51 for Mac

    
    <HEAD>
    
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Original:  Tom Khoury (twaks@yahoo.com) -->
    
    
    <!-- Begin
    function placeFocus() {
    if (document.forms.length > 0) {
    var field = document.forms[0];
    for (i = 0; i < field.length; i++) {
    if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
    document.forms[0].elements[i].focus();
    break;
             }
          }
       }
    }
    //  End -->
    </script>
    </HEAD>
    
    <!-- STEP TWO: Insert the onLoad event handler into your BODY tag  -->
    
    <BODY OnLoad="placeFocus()">
    
    <!-- STEP THREE: Copy this code into the BODY of your HTML document  -->
    
    <form>
    <input type=text size=10>
    </form>
    
    
    Code (markup):
     
    danielbruzual, Jul 7, 2006 IP
    ahkip likes this.
  3. ahkip

    ahkip Prominent Member

    Messages:
    9,205
    Likes Received:
    647
    Best Answers:
    0
    Trophy Points:
    310
    #3
    thx for the help, but it doesn't work. It highlight the textarea but the cursor is not inside....

    i am using a PDA with bar code scanner. The php page should automatically go to the textarea so i don't need to tap the screen at all
     
    ahkip, Jul 10, 2006 IP