disable all elements from all forms except <textarea>'s

  • Thread starter Bart Van der Donck
  • Start date
B

Bart Van der Donck

Hello,

I have a dynamic page of which I don't know how many forms will be on
it, neither which and how many elements will be in each form.

I use the following java script to disable all elements from all
forms:

var numberForms = document.forms.length;
var formIndex;
for (formIndex=0; formIndex<numberForms; formIndex++)
{
for(x=0;x<document.forms[formIndex].length;x++)
{ document.forms[formIndex].elements[x].disabled=true }
}

Now I want this to stay the same, except when an element is a
<textarea>. So basically: script must have the same functionallity
(disable all form elements), but not if the element is a textarea
(then it would remain enabled).

Is there a way to read out this <textarea> value in script ?

Thanks,
Bart
 
D

Dietmar Meier

Bart said:
Now I want this to stay the same, except when an element is a
<textarea>.

var aForms = document.forms,
nForms = aForms.length,
i;
for (i=0; i<nForms; i++) {
var aElems = aForms.elements,
nElems = aElems.length,
j;
for (j=0; j<nElems; j++) {
if (aElems[j].type != "textarea") {
aElems[j].disabled = true;
}
}
}

ciao, dhgm
 
R

RobB

Bart said:
Hello,

I have a dynamic page of which I don't know how many forms will be on
it, neither which and how many elements will be in each form.

I use the following java script to disable all elements from all
forms:

var numberForms = document.forms.length;
var formIndex;
for (formIndex=0; formIndex<numberForms; formIndex++)
{
for(x=0;x<document.forms[formIndex].length;x++)
{ document.forms[formIndex].elements[x].disabled=true }
}

Now I want this to stay the same, except when an element is a
<textarea>. So basically: script must have the same functionallity
(disable all form elements), but not if the element is a textarea
(then it would remain enabled).

Is there a way to read out this <textarea> value in script ?

Thanks,
Bart

var frm,
nForms = document.forms.length,
i = 0,
el,
els,
j,
nEls;
for (; i < nForms; ++i)
{
els = document.forms.elements;
for (j = 0, nEls = els.length; j < nEls; ++j)
{
el = els[j];
if ('undefined' != typeof el.disabled)
el.disabled = (el.type != 'textarea');
}
}
 
S

Stephen Chalmers

Bart Van der Donck said:
Hello,

I have a dynamic page of which I don't know how many forms will be on
it, neither which and how many elements will be in each form.

I use the following java script to disable all elements from all
forms:

var numberForms = document.forms.length;
var formIndex;
for (formIndex=0; formIndex<numberForms; formIndex++)
{
for(x=0;x<document.forms[formIndex].length;x++)
{ document.forms[formIndex].elements[x].disabled=true }
}

Now I want this to stay the same, except when an element is a
<textarea>. So basically: script must have the same functionallity
(disable all form elements), but not if the element is a textarea
(then it would remain enabled).

Is there a way to read out this <textarea> value in script ?

Thanks,
Bart

Just add 1 line to test the 'type' property:

var numberForms = document.forms.length;
var formIndex;

for (formIndex=0; formIndex<numberForms; formIndex++)
for(x=0;x<document.forms[formIndex].length;x++)
if(document.forms[formIndex].elements[x].type!='textarea')
document.forms[formIndex].elements[x].disabled=true;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top