Posts Tagged ‘javascript’

Dojo Javascript: Changing a FilteringSelect SELECT menu when another changes

February 17th, 2009

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!

Javascript: innerHTML, Select menu and Internet Explorer

February 12th, 2009

I’ve just had cause to pull in the contents of a SELECT menu using Javascript to help build up a webpage on the fly using the DOM. I had to do it this was a there were potentially 4,000 items for a select html menu (and so the user had to narrow it down by pre-selecting another menu) and then pulling the list of items from the server. The were also some optgroups in there (making using JSON or XML that bit harder) and there could, potentially, be some formatting information. Oh – and there could be 1 or 100 of these menus on the webpage.

The way I initally worked it, and which worked in Firefox, was to use:
(menuname being the id of the Domscripting gave me a clue and I eventually finished up with:
document.getElementById(‘menuname’).parentNode.innerHTML = ‘‘;
(i.e. recreating the entire select menu from scratch). It’s not nice, but it works!

Snippet: Yahoo YUI Datatable and Internet Explorer (IE)

October 3rd, 2008

I must remember that if I’ve using the Yahoo! (Yahoo User Interface) Datatable and the page validates and works in Firefox, but doesn’t work in Internet Explorer (IE), then the problem is most likely caused by an additional comma at the end of an array.

The YUI logger will not record any actions from that point on and no error will be reported by Microsoft Internet Explorer (at least not IE 6 or IE 7) – it’ll just stop the Javascript from working from the stray comma onwards.


%d bloggers like this: