Disable all fields on a Web form (ASP.net, HTML forms)

Hi,
 
Today we got a requirement to disable all the fields on the ASP.net form based on some conditions.
 
This can be easily done using JavaScript. Here is the code for it.

var inputs = document.getElementsByTagName(“input”);
for(var i = 0; i < inputs.length; i++) {
     // For applying background color and color.
     // inputs[i].style.backgroundColor = “#9fd4fe”;
     // inputs[i].style.color = “black”;
     inputs[i].disabled = true;
}
varselects = document.getElementsByTagName(“select”);
for(var i = 0; i < selects.length; i++) {
     selects[i].disabled = true;
}
vartextareas = document.getElementsByTagName(“textarea”);
for(var i = 0; i < textareas.length; i++) {
     textareas[i].disabled = true;
}
varbuttons = document.getElementsByTagName(“button”);
for(var i = 0; i < buttons.length; i++) {
     buttons[i].disabled = true;
}
varlinks = document.getElementsByTagName(‘a’);
for(var i = 0; i < links.length; i++) {
     links[i].disabled = true;
}

Hope this helps.
 

Happy Coding

Gopinath

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s