You can do this with jQuery . Say your HTML looks like this:
<input type="checkbox" onclick="toggleControls(this)"/>Controls Disabled <table id="myTable"> <tr> <td>Name: <input type="text" /></td> <td>Select: <input type="radio" /></td> </tr> .....
The toggleControls () function to disable / enable all controls inside the table (this means that all text fields, buttons, check boxes, radio buttons and drop-down lists) look like this:
<script> function toggleControls(e){ $('#myTable input,select,textarea').attr('disabled',e.checked); } </script>
JQuery css selectors allow you to disable / enable single line controls. With plain old javascript, the function would look like this:
var myTable = document.getElementById("myTable"); var controls= myTable.getElementsByTagName("input"); // Repeat the previous line for "select" and "textarea" for(i = 0; i < controls.length; i++) { control = controls[i]; control.disabled = !control.disabled; }
source share