views:

56

answers:

2

Hi, I have many controls in table and I want to disable all the controls using JavaScript upon clicking of some checkbox.

I have google and found that we can't disable table instead all controls through loop. Please suggest me, what is better idea

Thanks

+1  A: 

You can check this solution, but its require Jquery. http://stackoverflow.com/questions/786175/disabling-controls-within-a-table-jquery-javascript

Maksim Kondratyuk
+1  A: 

Here's a simple script to do this.

var table = document.getElementById('yourTableId');
var inputs = table.getElementsByTagName('INPUT');
var links = table.getElementsByTagName('A');

for (var i = 0; i < inputs.length; i++) {
    inputs[i].disabled = true;
}

for (var i = 0; i < links.length; i++) {
    // There are better ways to disable links, but 
    // this is the shortest code to do it
    links[i].onclick = 'return false;';
}

This should run very efficiently, though it won't change the style of the table very much. Maksim's answer has a good solution for making the table look disabled.

Dan Herbert