views:

113

answers:

0

I'm having some problems with a select all/ none function. (I didn't write it, I'm trying to fix it!) It currently looks like this:

rsfindmod.SelAll = function(){
    document.getElementById("ListBox").selectAll();
    document.getElementById("ListBox").focus();
}

It's being used on a dynamically generated set of links, so there's no set number of items in this listbox. This seems to work most of the time, but randomly it only selects those which are visible at the time. Scrolling the list or hitting the button again seems to normally make it work as expected.

My first (Obvious?) thought was to replace the function entirely with the one from this link for testing: http://viralpatel.net/blogs/2009/06/listbox-select-all-move-left-right-up-down-javascript.html

Trouble is that I can't get this one to work whatsoever! This gives me the error that

listbox.options is not defined

Any thoughts please? I'm by no means certain whether it's the original function at fault, or something in the generation of this listbox.

As per the comments, listbox posseses the selectAll() method by default when working with XUL, therefore I'm becoming relatively sure it's a problem with how the contents of the listbox are built? This looks like this:

rsfindmod.onLoad = function() {

    var parElement = document.getElementById("ListBox");
    var prefservice = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
    var prefs = prefservice.getBranch("extensions.rsfindmod.");

    // create a listitem for each result
        for(var i=0; i<window.arguments[0].inn.thelinks.length; i++){
        var newElement =  document.createElement("listitem")
        newElement.setAttribute("id", ("listitem" + i.toString()));
        newElement.setAttribute("label", window.arguments[0].inn.thelinks[i]);
        parElement.appendChild(newElement);

    }

.....
Some more code for highlighting specific links in here, but junking that produces the same issues, and it's pretty irrelevant here.
.....