tags:

views:

136

answers:

2

how to disable all listbox in a form

+3  A: 
$('#formId select').attr('disabled', 'disabled');

Edit: oops, thought I saw a jquery tag. Anyway:-

for (i = 0; i < theform.length; i++) {
        var formElement = theform.elements[i];
        if (formElement.tagName === "SELECT") {
            formElement.disabled = true;
        }
}
Gavin Gilmour
shouldn't that comparison against the tag name be against uppercase 'SELECT'? or be all converted to lower case... if(formElement.tagName.toLowerCase() === 'select'){...
scunliffe
you're right of course, though I'd probably prefer Marius's answer entirely. damn frameworks turning the brain to mush!
Gavin Gilmour
+3  A: 

Just to improve on Gavin's correct answer:

var selects = theform.getElementsByTagName("select");
for (i = 0; i < selects.length; i++) {
  selects[i].disabled = true;
}
Marius