Forum Moderators: open

Message Too Old, No Replies

all form fields disabled without putting "disabled" on each one?

         

partha

1:00 am on Jan 10, 2005 (gmt 0)

10+ Year Member



Is there a way (using JS or html or php or anything) to make all the form fields on a page disabled or readonly? putting the "disabled" attribute on all the fields (or even one of the fields for that matter) is not an option in my circumstances.

Is there another way to make fields disabled or readonly?

BlobFisk

9:43 am on Jan 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi partha,

This is relatively straight forward. If you wrap your form in a layer with an ID of (say) formHolder, you can use the getElementsByTagName to change all elements of a certain tag:


function disableInputs() {

theInputs = new Array();
theInputs = document.getElementById('formHolder').getElementsByTagName('input');
for (i=0; i<theInputs.length; i++) {
theInputs[i].disabled=true;
}
}

One thing to remember is to put your Reset and Submit input buttons outside the div so that they are not affected by the script. You can also apply this to select lists and textareas.

HTH

partha

4:31 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



thanks