By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Bart Van der Donck wrote:
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[i].elements,
nElems = aElems.length,
j;
for (j=0; j<nElems; j++) {
if (aElems[j].type != "textarea") {
aElems[j].disabled = true;
}
}
}

ciao, dhgm
Jul 23 '05 #2

P: n/a
Bart Van der Donck wrote:
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[i].elements;
for (j = 0, nEls = els.length; j < nEls; ++j)
{
el = els[j];
if ('undefined' != typeof el.disabled)
el.disabled = (el.type != 'textarea');
}
}

Jul 23 '05 #3

P: n/a
Bart Van der Donck <ba**@nijlen.com> wrote in message
news:b5**************************@posting.google.c om...
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;
--
S.C. http://makeashorterlink.com/?H3E82245A

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.