A
In my current example, I have an array and want to disable the elements in the array - but only if they have a property type that equals either ‘radio’ or ‘checkbox’. Looping through the array, this works: #1
var t = this.inputs[i].type || null;
if(t==='checkbox' || t==='radio') { this.inputs[i].disabled=true; }
But it annoys me in this sort of cases that I have to type the variable’s name twice. I tried this instead which didn’t work: #2
t==='checkbox' || 'radio'
And this which worked in Firefox and Chrome, but not in IE8: #3
t==='checkbox' | 'radio'
Surely, there must be an shorter way of doing it than #1 above?
It responds perfectly to both the CTRL key and the SHIFT key.
The odd thing about #2 is that there was a object in that array which was not an HTMLElement and had no .type property at all [it was an Array(String)] - but it still “passed the test” of the if(t===‘checkbox’ || ‘radio’) and went into the following code block {}.
Ha ha - thanks! I forgot to test with any other keys than just ctrl and shift! It proves that no matter which key I press, it has the same effect - obviously, as you say, the number 16 always evaluates to true! Silly me …
And thanks for your other suggestion with " who.disabled= t==‘checkbox’ || t=='radio; " !