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

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer OK, now I know what you want. There is currently… May 16, 2026 at 5:58 pm
  • Editorial Team
    Editorial Team added an answer You shouldn't need to parse your JSON. Set the dataType… May 16, 2026 at 5:58 pm
  • Editorial Team
    Editorial Team added an answer You shouldn't do that. There is not a thing called… May 16, 2026 at 5:58 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Can anyone please tell me how do I make this script run in IE
Question: Can anyone please provide a full code example that shows how one does
this is no longer relevant since iOS4+ - so please stop downvoting! or at
I'm embarrassed by the 'basicness' of this question, but after wasted hours, here goes.
I was wondering if there's anyone having an idea how to tackle with the
This is code for a costume contest application I'm presently building. There will be
I'm using this: from twisted.web.client import getPage df = getPage(url) # there is some
I would like to do some functionality like this app for iphone: http://www.ezraschartbooks.com/Site/Home.html I
I am looking to create a function that could create a fade-in/fade-out function on
I want to traverse through all the elements of an word document one by

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.