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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:49:53+00:00 2026-06-02T17:49:53+00:00

I have two dropdown list and an inputbox. When a value from the dropdown

  • 0

I have two dropdown list and an inputbox. When a value from the dropdown list is selected a specific values should be preselected in the other two controls.

Here is my knockout code:

var viewModel = {
    templates: ko.observableArray(["Template1", "Template2"]),
    //when Template2 is selected Spanish should be preselected from the languages select list and name of the template should be written in the folderName inputbox (Template2)
    //when Template1 is selected French should be preselected and name of the template should be written in the folderName inputbox (Template1)
    languages: ko.observableArray(["English", "Spanish", "French"]),
    folderName: ko.observable()
}

ko.applyBindings(viewModel);

Here is my sample html code:

<select id="templates" data-bind="options: templates"></select>

<div>
<input data-bind="value: folderName"/>
</div>

<div>
<select id="languages" data-bind="options: languages"></select>
</div>  

When Template2 is selected Spanish should be preselected from the languages select list and name of the template should be written in the folderName inputbox (Template2).
When Template1 is selected French should be preselected and name of the template should be written in the folderName inputbox (Template1)

Fiddle: http://jsfiddle.net/PsyComa/Q8unN/19/

I am rather new to javascript and every help with working example will be greatly apreciated. Thank You!

  • 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-06-02T17:49:54+00:00Added an answer on June 2, 2026 at 5:49 pm

    This is more universal code. If you’ll fill the templateLanguageMapwith the template-language pairs, this code will solve your problem. You won’t have to write a lot of if statements. Good Luck!

    <select id="templates" data-bind="options: templates"
        onchange="onTemplateChange(value);"></select>
    
    <div>
    <input id="folderName"  data-bind="value: folderName"/>
    </div>
    
    <div>
    <select id="languages" data-bind="options: languages"></select>
    </div>
    

    JavaScript:

        var viewModel = {
            templates: ko.observableArray(["Template1", "Template2"]),
            //when Template2 is selected Spanish should be preselected from the languages select list and name of the template should be written in the folderName inputbox (Template2)
            //when Template1 is selected French should be preselected and name of the template should be written in the folderName inputbox (Template1)
            languages: ko.observableArray(["English", "Spanish", "French"]),
            folderName: ko.observable()
        }
    
        var selectTemplates = document.getElementById('templates');
        var selectLanguages = document.getElementById('languages');
        var inputFolderName = document.getElementById('folderName');
    
        var templateLanguageMap = {"Template1":"Spanish", "Template2":"French"};
    
        onTemplateChange = function(value){
            inputFolderName.value = value;
            for ( var i = 0; i < selectLanguages.options.length; i++ ) {
                if ( selectLanguages.options[i].value == templateLanguageMap[value]) {
                    selectLanguages.options[i].selected = true;
                    return;
                }
            }
        }
    
        ko.applyBindings(viewModel);
        onTemplateChange(selectTemplates.value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
I have three DropDown List Controls.each dropdown contains the static values 1,2,3,4 what i
I have two dropdown lists, the second should only be displayed when the value
I have created a populated dropdown list in HTML. When the two dropdowns have
I have two dropdown lists (one dynamically populated, the other not) that determine the
I have two nested DropDownLists (the value selected in the 1st ddl will limit
I have two dropdown lists, one containing a list of countries and one for
Afternoon All, I have a dropdown list which extracts data from my SQL database
I have two items in the Dropdown list and i have the code for
I have two search buttons on a page, one linked to a dropdown list

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.