Press "Enter" to skip to content

Dojo Javascript: Changing a FilteringSelect SELECT menu when another changes

Here’s a bit of Dojo Javascript which will allow you to dynamically change a SELECT sub menu (technically a “FilteringSelect” menu with an id of “secondFilteringSelectId”) when the first SELECT menu is changed (another FilteringSelect menu with an id of “firstFilteringSelectId”). It uses the Dojo’s ItemFileReadStore method to fetch an ajax page (called ajax) before populating the menu. It also has some caching built in to reduce the number of calls to the server and associated network traffic.

dojo.addOnLoad(function() {
    dijit.byId('firstFilteringSelectId').onChange=function() {
function fFirstFilteringSelectIdChanged(thisValue) {
    if (aSecondFilteringCache[thisValue]==undefined) {
        var myStore=new{url:'ajax?setting='+thisValue});
        var gotList = function(items, request) {
        var gotErrors=function(error,request) {
            alert('Request failed:'+error);
        var request=myStore.fetch({onComplete:gotList,onError:gotErrors});
    } else {[thisValue];

I am just learning Dojo though, so there could be a much better/sensible way of doing this: let me know if you know/find it!