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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:33:00+00:00 2026-05-20T12:33:00+00:00

I have below code working as desired but the on select works only from

  • 0

I have below code working as desired but the on select works only from the second select change.

Any idea how to fix that?

working sample

<html>
<head>

<title>select & select</title>


<script type='text/javascript'>

var select2data = {

  'English': [['One', 1], ['Two', 2], ['Three', 3]],
  'Spanish': [['Uno', 1], ['Dos', 2], ['Tres', 3]]
};


function change_second_select(){
var sel1 = document.getElementById('select1')
  , sel2 = document.getElementById('select2');
sel1.onchange = function() {
  var os = select2data[sel1.value]; // Get the options required by select1.
  if (os) {
    sel2.options.length = 0; // Clear the options for select2.
    for (var i=0; i<os.length; i++) {
      var o = new Option(os[i][0], os[i][1]);
      try { // Add each option, allowing for browser differences.
        sel2.add(o);
      } catch (ex) {
        sel2.add(o, null);
      }
    }
    sel2.selectedIndex = 0;

  }
  return true;
};
}


</script>


<select id="select1" onchange="change_second_select();">
<option value="English">English</option>
<option value="Spanish">Spanish</option>
</select>
<select id="select2">

</select>


</head>
    </html>
  • 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-20T12:33:00+00:00Added an answer on May 20, 2026 at 12:33 pm

    Change your change_on_select to as below:

    Working example @ http://jsfiddle.net/3dCyw/1/

    function change_second_select(){
    var sel1 = document.getElementById('select1')
      , sel2 = document.getElementById('select2');
      var os = select2data[sel1.value]; // Get the options required by select1.
      if (os) {
        sel2.options.length = 0; // Clear the options for select2.
        for (var i=0; i<os.length; i++) {
          var o = new Option(os[i][0], os[i][1]);
          try { // Add each option, allowing for browser differences.
            sel2.add(o);
          } catch (ex) {
            sel2.add(o, null);
          }
        }
        sel2.selectedIndex = 0;
    
      }
      return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below code but it is not working. Is this correct? var
I have working code below for collision of two circles, but now I have
EDIT: See my working code in the answers below. In brief: I have a
So far i have got the code below which works lovely when trying an
i have got below code which is working fine: public abstract class Beverage {
I have the below code that was working fine until I tried adding the
Any ideas regarding why the WPF XAML code I have is not working. I'm
I have the below code working fine up to 150 consecutive threads. Anything over
I am using JQuery. I have below JQuery Code which working fine in Firefox,
I am using JQuery and I have below code. $(#departure_city).change(function() { $.ajax( { type:'post',

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.