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

  • Home
  • SEARCH
  • 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 691809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:35:03+00:00 2026-05-14T02:35:03+00:00

In code-behind I can do this to select something: // Select item in first

  • 0

In code-behind I can do this to select something:

// Select item in first DropDownList
myCascadingDropDown_1.SelectedValue = itemValue_1+":::"+itemText_1;

// Select item in second DropDownList
myCascadingDropDown_2.SelectedValue = itemValue_2+":::"+itemText_2;

How can I do this in JavaScript?

(I’m aware, that I could search the list and set the selectedIndex property for each dropdown, but I have many items and i’m very lazy.)

EDIT:

npups answer works: I can select my desired item in the first dropdownlist. The problem is however, that new values based on that selected item (it is a CascadingDropDown, remember?) don’t show in the second dropdown so I can’t select anything there. I would need to somehow invoke the update method of the second dropdown manually: any suggestions?

  • 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-14T02:35:04+00:00Added an answer on May 14, 2026 at 2:35 am

    Check this out:

    <select id="foo">
      <option value="bar">bar</option>
      <option value="baz">baz</option>
      <option value="bork">bork</option>
    </select>
    
    <script type="text/javascript">
      var selectElem = document.getElementById('foo');
      selectElem.value = 'baz';
    </script>
    

    Setting the value of the select element fixes that.

    Firefox gets it right even if you just use the tags’ content as values (instead of specifying a value in the option’s value attribute). Not sure about other browsers.

    EDIT, more stuff:
    So there is some other select (or equivalent) that is updated by some harmonizing function when the first select changes?
    Here, i have it in the first select’s onchange. When the selected element is set with this “value-setting” technique, the onchange isn’t triggered. Though, one can call the harmonizing function manually when you change the first select. I show two different ways (both in comments) below.

    <select id="foo" onchange="harmonize();">
      <option value="bar">bar</option>
      <option value="baz">baz</option>
      <option>bork</option>
    </select>
    
    <select id="foo2">
     <option value="0">This</option>
     <option value="1">That</option>
    </select>
    
    
    <script type="text/javascript">
       var select0 = document.getElementById('foo');
       var select1 = document.getElementById('foo2');
       select0.value = 'baz';
       // alternative 1: call harmonize();
       // alternative 2: call select0.onchange();
    
       function harmonize() {
         if (select0.value==='baz') {
           select1.value = '1';
         }
         else {
           select1.value = '0';
         }
       }
    </script>
    

    I didn’t bother to hide global variables etc. here, but of course that is a good idea.

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

Sidebar

Related Questions

ASP.Net: In code-behind I can simulate <%# Eval(Property)%> with a call to DataBinder.Eval(myObject,Property); How
I place using namespace in a view code behind but i can't call any
How can i set value(in code behind) for an element declared in the xslt
I am currently publishing code behind .aspx in SharePoint. I can automatically publish the
In my code behind I wire up my events like so: protected override void
I'm using my code-behind page to create a save button programmatically: Button btnSave =
I know about code-behind files, but what is the best real-world way of Designers
Why are the code-behind pages for an ASP.NET web application locked at run time?
Is it possible to set code behind a resource dictionary in WPF. For example
I created a single page (with code behind .vb) and created Public intFileID As

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.