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!
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 ofifstatements. Good Luck!JavaScript: