0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You can check this solution, but its require Jquery. Disabling controls within a table - JQuery/Javascript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.