Reputation: 281
I have a number of combo boxes where I would like values to change when other values are selected. I am fairly novice at JavaScript, here is what I have gathered from other colleagues. The ideal workflow would be if Electronic Waste is selected in cbRequestType then the only items which populate are those below, such as copy machine, printer, etc. This does not work, what could I be missing?
Additionally, my application already maintains a function which populates the cbEWASTE drop down from a database. I would like to by pass that function and populate the combo box on change.
dijit.byId("cbRequestType").on('change', function(MFValue) {
if (MFValue == 'E-WASTE') {
dijit.byID("cbEWASTE").set('value', 'Copy Machine');
}
else if (MFValue == '...') {
dijit.by.ID('cbEWASTE').set('value', 'Printer');
}
});
Upvotes: 0
Views: 925
Reputation: 44685
You're calling the incorrect method. There is no function called byID()
or by.ID()
like you used inside the change event. Correct usage would be:
dijit.byId("cbRequestType").on('change', function(MFValue) {
if (MFValue == 'E-WASTE') {
dijit.byId("cbEWASTE").set('value', 'Copy Machine');
}
else if (MFValue == '...') {
dijit.byId('cbEWASTE').set('value', 'Printer');
}
});
Remember, function names are case sensitive, so be careful with calling certain functions. Then the next thing, when you set the value, you're not setting the dropdown, you're simply setting the current value in the textbox-part of the combobox.
If you want to populate the dropdown, you should change the store of the combobox, for example (Dojo 1.8 and higher):
registry.byId("cbEWASTE").set("store", new Memory({
data: [{
id: "Printer",
name: "Printer"
}]
}));
An example can be found on JSFiddle.
Upvotes: 2