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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:37:59+00:00 2026-05-16T12:37:59+00:00

Given the the following javascript function, function switch_plug_drop_down(plug_id) { selector = document.getElementById(‘group_1’); if (plug_id

  • 0

Given the the following javascript function,

function switch_plug_drop_down(plug_id) {
      selector = document.getElementById('group_1');
      if (plug_id == "1") {selector.options['product_253'].selected = true;}
      if (plug_id == "2") {selector.options['product_217'].selected = true;}
      if (plug_id == "3") {selector.options['product_254'].selected = true;}
      if (plug_id == "4") {selector.options['product_255'].selected = true;}
      if (plug_id == "5") {selector.options['product_256'].selected = true;}
  }

and the following HTML select element (generated by cs-cart)

<select name="product_data[245][configuration][1]" id="group_1" onchange="fn_check_exceptions(245);fn_check_compatibilities(1,'select','S');"> 
    <option id="product_255" value="255"  >Power Adapter Plug Choice AUS<span class="price"></span></option> 
    <option id="product_217" value="217"  >Power Adapter Plug Choice EURO<span class="price"></span></option> 
    <option id="product_256" value="256"  >Power Adapter Plug Choice JAPAN<span class="price"></span></option> 
    <option id="product_254" value="254"  >Power Adapter Plug Choice UK<span class="price"></span></option> 
    <option id="product_253" value="253" selected="selected"} >Power Adapter Plug Choice USA / Canada<span class="price"></span></option> 
</select> 

This works fine in FF 3.6.8, Chrome 5.0.375, but fails in IE 8 (browser mode 8, document mode IE8 Standard)

I am getting an error in IE 8’s javascript debugger :

'selector.options.product_217' is null or not an object

and this corresponds to selector.options['product_217'].selected = true; in the js code above.

Also, jQuery 1.3.n is on the site and works fine.

Does anybody know what is going on and how to fix it?

UPDATE:

I implemented Tim’s solution, but had the values loaded on automatically:

selector = document.getElementById('group_1');
for (var i = 0; i < selector.children.length; ++i) {
    var child = selector.children[i];
    if (child.tagName == 'OPTION') optionIndicesByPlugId[child.value]=''+i;
}

(this code came from this SO question’s first answer)

and the plug_id that is passed to the switch_plug_drop_down function is not a 1-5 number anymore but the value in the 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-16T12:37:59+00:00Added an answer on May 16, 2026 at 12:37 pm

    A select’s options property is not guaranteed to contain properties corresponding to the value of each option. Most browsers (not IE) implement it as HTMLOptionsCollection, which is confusingly specified: the DOM spec and MDC both seem to suggest that non-numeric properties of options should correspond to names and ids of option elements. So, the most cross-browser approach is to use numeric properties instead.

    The easiest way to set which option is currently selected is to use the select’s selectedIndex property:

    var optionIndicesByPlugId = {
        "1": 4,
        "2": 1,
        "3": 3,
        "4": 0,
        "5": 2
    };
    
    function switch_plug_drop_down(plug_id) {
        var selector = document.getElementById('group_1');
        selector.selectedIndex = optionIndicesByPlugId[plug_id];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following javascript (jquery) $(#username).keyup(function () { selected.username = $(#username).val(); var url =
Given the following javascript: function foo(selectControl) { ... } and the following html: <select
Given the following snippet of javascript in a scope: var x = 10; function
Given the following JavaScript class definition: var Quota = function(totalMinutes){ this.totalMinutes = parseInt(totalMinutes ||
Given the following JavaScript: var someFunction = function(id) { //do some stuff var modifyId
I use the following Javascript function.It will not work.It will give the Undefined Error
Given a string like the following in JavaScript var a = 'hello world\n\nbye world\n\nfoo\nbar\n\nfoo\nbaz\n\n';
Installing egit on indigo im given following options : I've just checked 'Eclipse Egit'
Given the following code: $(.force-selection).blur(function() { var value = $('matched-item').val(); //check if the input's
Given the following Javascript, would it be better/more idiomatic to inject the MyService object

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.