Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7725345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:54:52+00:00 2026-06-01T04:54:52+00:00

The following code works fine in most browsers but it won’t work in Internet

  • 0

The following code works fine in most browsers but it won’t work in Internet Explorer CE Mobil and I can’t for the life of me figure out why.

function autofocus() {
    var el = document.getElementById("autofocus");
    if (el === null) {
        return;
    } else if (el.tagName.toUpperCase() == "SELECT") {
        if (el.selectedIndex == -1) {
            el.options[0].selected = true;

        }
    }
    el.focus();
}

$(window).ready(function () {
    autofocus();  
});​

It works perfectly in all the regular browsers I have tried but in Internet Explorer Mobile it seems to focus on the select list itself which means it’s not possible to navigate the various options without clicking one. Maybe if I click one of the options instead?. See http://jsfiddle.net/mhenrixon/sbwCv/19/ for an example of what is not working.

EDIT: It does not have to do with the selectedIndex per se since most of the time there will be a selectedIndex like 15, 5, 27 or whatever. Just not -1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:54:53+00:00Added an answer on June 1, 2026 at 4:54 am

    On my Samsung Saga, I’m running:

    Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11) VZW:SCH-i770 PPC 320×320

    and the problem on this browser is the jQuery ready function.

    If instead you use <body onload="autofocus()"> the <select> will have its first option selected. And that option is indeed focused; if I use the optical mouse, I can right-arrow to a different option and space-bar to select it.

    So here’s the test case I’ve ended up with:

    <html>
    <head>
    <title>Test</title>
    <!-- script type="text/javascript" src="jquery-1.4.2.js" -->
    <script type="text/javascript">
    function autofocus() {
        var el = document.getElementById("autofocus");
        if (el === null) {
            return;
        } else if (el.tagName.toUpperCase() == "SELECT") {
            if (el.selectedIndex == -1) {
                el.options[0].selected = true;
            }
        }
        el.focus();
    }
    
    /*
    $(window).ready(function () {
        autofocus();  
    });
    */
    </script>
    </head>
    <body onload="autofocus()">
    <select autofocus="autofocus" id="autofocus" multiple="multiple">
        <option value="0">0:17,00st</option>
        <option value="P11">P11:1918,00st</option>
        <option value="P12">P12:100,00st</option>
    </select>
    </body>
    </html>
    

    And of course it works on desktop browsers as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code works just fine. But it seems so verbose, surely there is
I had my code work fine yesterday, but today I can no longer get
The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1,
The following code works fine for Visual C++ 2008. However, when comes to Visual
The following code works fine #define open { #define close } #include<stdio.h> #define int
The following code works fine : std::map<int, int>& m = std::map<int, int>(); int i
The following code works fine. class A { private: int _value; public: class AProxy
Following XLST code works fine :- <?xml version=1.0?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version=1.0> <xsl:template match=/> <xsl:for-each
I have the following code which works fine. However, I only want to return
I have the following code that works fine in IE: <HTML> <BODY> <script language=JavaScript>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.