Changing Microsoft’s TabStrip disabled property via javascript.

This task can be a little tricky, so after messing with it’s HTC (TabStrip.htc) here is how you do it:


To enable tab:


document.all.tags(“TabStrip”)[0].getTab(0).setAttribute(“disabled”, false);


To disable tab:


document.all.tags(“TabStrip”)[0].getTab(0).setAttribute(“disabled”, true);


* You can select other tabs of course or loop over them to disable\enable all of them at once (as needed).


Maybe it can save someone else the time I’ve wasted on it.


Back to code…

 

Oren Ellenbogen

 

3 thoughts on “Changing Microsoft’s TabStrip disabled property via javascript.

  1. Hello Oren,

    I tried the code you supplied for this and it didn’t work. I couldn’t, for example, retrieve my own tabstrip from the document.all.tags collection.

    Instead, I just used document.getElementById((name of my tab strip here)) which returned an object oTs.

    I named all my tabs so I could use oTs.getTab((name of a tab here)) rather than oTs.getTab(integer), and this did return an object oTab. However, the htc then fell over when I tried to use setAttribute:

    oTab.setAttribute(‘disabled’, true) for example, it fell over inside the htc, complaining about an "item" being "null".

    Looking through the htc I noticed that there was another function there: getItem, which seem to do something very similar to getTab. I tried it

    oTab = oTs.getItem((name of a tab here)) and lo and behold: setAttribute worked perfectly on that.

    It’s all bloody voodoo to me, but seein’ as I got it to work I reckoned that you might be interested in this variation.

    Regards

    Pino Carafa

  2. Further to the above. I realised why I couldn’t get my TabStrip out of the tags collection. Just shows you how much of a newbie I am……

    I thought I needed to pass the name of my TabStrip as the argument. But of course I always have to pass ‘TabStrip’. document.all.tags(‘TabStrip’) gives you a collection of all the TabStrips on your document.

    After this insight the only comment I’d have to add is that Oren’s example must be based on the premise that there is precisely one TabStrip on the document, so that document.all.tags(‘TabStrip’)[0] will give you a handle on that one and only TabStrip. To be honest, a document with more than one of those would, from a design perspective, be rather suspect. But it’s possible. If you have a document with multiple TabStrips on it, you can use item to retrieve the correct one. document.tags(‘TabStrip’).item(‘Fred’) will return the TabStrip named ‘Fred’. Or you can use document.getElementById(‘Fred’) or even document.all.Fred …. provided you haven’t done something stoopid like add a number of elements with that same id on the document.

    What would be interesting is to see whether there is any difference in a Tab returned through document.all.tags(‘TabStrip’).item(‘Fred’).getTab(‘Wilma’) as opposed to document.getElementById(‘Fred’).getTab(‘Wilma’) – in both cases an object is retrieved that does look identical, but I’ll leave it up to the interested reader (hah!) to check whether perhaps .setAttribute does work in one case and not in the other.

Comments are closed.