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 1035457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:32:43+00:00 2026-05-16T14:32:43+00:00

Can anyone please why does this javascript work only in firefox? function filter(obj, what,

  • 0

Can anyone please why does this javascript work only in firefox?

function filter(obj, what, where)
{
    var v = obj.value;
    var d = document.getElementById(where).getElementsByTagName('optgroup');

    if (v > 0)
    {
        for (var i = 0; l = d.length, i < l; i++)
        {
            d[i].className = 'hide';
            if (d[i].id == what + '_' + v)
                d[i].className = '';
        }
    }
    else
    {
        for (var i = 0; l = d.length, i < l; i++)
            d[i].className = '';
    }
}

I tested it in opera, IE7 and chrome but it doesn’t work! Opera error console doesn’t show any javascript errors when the page is loaded!

This javascript creates three level auto populating drop down boxes…

I don’t know whether it’s necessary or not but I post the HTML code too…

State:
<select name="state" onchange="filter(this, 'state', 'district');">
    <option value="0"></option>
    <option value="1">State 1</option>
    <option value="2">State 2</option>
    <option value="3">State 3</option>
</select>

District:
<select name="district" id="district" onchange="filter(this, 'district', 'city');">
    <option value="0"></option>
    <optgroup id="state_1" label="State 1">
        <option value="1">District 1</option>
        <option value="2">District 2</option>
    </optgroup>
    <optgroup id="state_2" label="State 2">
        <option value="3">District 3</option>
    </optgroup>
    <optgroup id="state_3" label="State 3">
        <option value="4">District 4</option>
        <option value="5">District 5</option>
        <option value="6">District 6</option>
    </optgroup>
</select>

City:
<select name="city" id="city">
    <option value="0"></option>
    <optgroup id="district_1" label="District 1">
        <option value="1">City 1</option>
        <option value="2">City 2</option>
        <option value="3">City 3</option>
    </optgroup>
    <optgroup id="district_2" label="District 2">
        <option value="4">City 4</option>
        <option value="5">City 5</option>
    </optgroup>
    <optgroup id="district_3" label="District 3">
        <option value="6">City 6</option>
        <option value="7">City 7</option>
    </optgroup>
</select>
  • 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-05-16T14:32:43+00:00Added an answer on May 16, 2026 at 2:32 pm

    ok I know whats happening. It works. IE and possibly other browsers don’t support many css properties on <optgroup>. I’m assuming you have something like this:

    optgroup.hide {display:none;}
    

    The above works in firefox but doesn’t in IE. I used firebug lite to see that IE indeed applied the ‘hide’ class to the optgroup. I then tried changing the background to red instead of display:none and it works in IE. I think you have to find another way of hiding the optgroup. Maybe remove it from the select altogether and add it back in afterwards.

    See my sample code below.

    <!doctype html>
    <html>
    <head>
    <title></title>
    <style type="text/css">
        .hide{background:red}
    </style>
    <script type="text/javascript">
    function filterSelect(obj, what, elID)
        {
            alert(elID);
            var v = obj.value;
            var d = document.getElementById(elID).getElementsByTagName('optgroup');
    
            if (v > 0)
            {
                for (var i = 0; l = d.length, i < l; i++)
                {
                    d[i].className = 'hide';
                    if (d[i].id == what + '_' + v)
                        d[i].className = '';
                }
            }
            else
            {
                for (var i = 0; l = d.length, i < l; i++)
                    d[i].className = '';
            }
        }
    
        </script>
    </head>
    
    <body>
    
    State:
    <select name="state" onchange="filterSelect(this, 'state', 'district');">
        <option value="0"></option>
        <option value="1">State 1</option>
        <option value="2">State 2</option>
        <option value="3">State 3</option>
    </select>
    
    District:
    <select name="district" id="district" onchange="filterSelect(this, 'district', 'city');">
        <option value="0"></option>
        <optgroup id="state_1" label="State 1">
            <option value="1">District 1</option>
            <option value="2">District 2</option>
        </optgroup>
        <optgroup id="state_2" label="State 2">
            <option value="3">District 3</option>
        </optgroup>
        <optgroup id="state_3" label="State 3">
            <option value="4">District 4</option>
            <option value="5">District 5</option>
            <option value="6">District 6</option>
        </optgroup>
    </select>
    
    City:
    <select name="city" id="city">
        <option value="0"></option>
        <optgroup id="district_1" label="District 1">
            <option value="1">City 1</option>
            <option value="2">City 2</option>
            <option value="3">City 3</option>
        </optgroup>
        <optgroup id="district_2" label="District 2">
            <option value="4">City 4</option>
            <option value="5">City 5</option>
        </optgroup>
        <optgroup id="district_3" label="District 3">
            <option value="6">City 6</option>
            <option value="7">City 7</option>
        </optgroup>
    </select>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What does this mean? (function (x,y)){…}){a,b); in JavaScript Please anyone explain and
Can anyone please explain the comma operator in FOR statement? function funct_1(c){ for (var
Can anyone please explain me what delegateEvents in backbone.js does? The documentation did not
It does not matter what programming language. Can anyone please give me an idea
Can anyone please tell me how to extract this kind of data : [{number:8457215152,type:Cell,state:LA,country:US,tz:CT,zip:70546,msa:0},{number:4363685555,type:Cell,state:LA,country:US,tz:CT,zip:70546,msa:0}]
Can anyone please offer some insight into this for me? I'm coming from a
I don't understand the each() and the list() function that well. Can anyone please
Can anyone please tell/suggest me how can i store and retrieve comments multiple/different values
Can anyone please explain me the use of development certificates and how I can
Can anyone please explain how to replace the values of one column with the

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.