Javascript Selectbox refresh necessary in YUI 3, when selecting none?

Posted by Jasie on Stack Overflow See other posts from Stack Overflow or by Jasie
Published on 2009-07-29T17:40:59Z Indexed on 2010/05/07 4:08 UTC
Read the original article Hit count: 298

Filed under:
|
|
|

Hi all,

I'm using YUI 3 to let someone click "Select All" or "Select None" and then have the selectbox select all the items or unselect all of them, respectively. Here's my code:

// This selects all
    Y.on('click',function (e) {
            selectBoxNode.get("options").each(function () {
               this.removeAttribute('selected');
               this.setAttribute('selected','selected');
            });
        }, selectAllNode
    );

// This selects none
   Y.on('click',function (e) {
            selectBoxNode.get("options").each(function () {
               this.setAttribute('selected','false');
               this.removeAttribute('selected');
            });
            selectBoxNode.('selectedIndex',-1);
        }, selectNoneNode
    );

selectAllLink, selectNoneLink, and selectBoxNode are self-evident, properly returned Nodes. Update: selectAll works, I had to manually remove the 'selected' attribute for each and re-add it.

The selectNoneLink doesn't work: it unselects only the elements that weren't before selected... although DOM inspection shows that the selectedIndex attribute is indeed changed to -1, so maybe it needs a refresh?

Any help would be appreciated. If this happens in all frameworks, that would be nice to know as well.

Thanks!

© Stack Overflow or respective owner

Related posts about select

Related posts about yui