PDA

View Full Version : is there any way to disable all elements in form without looping?


frontline
07-21-2003, 07:04 AM
Hello
i need to disable all form elements the only why i found to do it is
ti loop throw all the alements.length...but its can be very heavy task for the browser if
it has lots of elements ,my question is : is there any better cpu effective way to do it?
thanks

glenngv
07-21-2003, 07:33 AM
How many elements the page has? I have a page that contains 304 elements that are being disabled/enabled at the same time after certain events and I don't have to worry about speed. The effect on performance is minimal. If you just want to disable the elements as they load, just put the disabled attribute for each element. But if you want to change their state after the page loads, there's no choice but to loop thru each item.

fredmv
07-21-2003, 08:09 AM
I agree with glenngv, looping is really your only option if you want it to be done dynamically. Otherwise you're basically going to have to hardcode in every element you want to disable.

So for disabling elements after the page has loaded you could do something like this:


<script type = "text/javascript">

window.onload = function()
{
for(i=0; i<document.forms[0].elements.length; i++)
{
document.forms[0].elements[i].disabled = true;
}
return;
}

</script>


Well, good luck with everything.

Vincent Puglia
07-21-2003, 12:29 PM
Hi,

Is the app inter or intranet? How many forms/elements on the page? And what browser(s) are you talking about. Not all browsers recognize the 'disable' property. So, if you are talking about an internet application, you'll have to use the 'focus' and 'blur' properties/event handlers.

Other possible solutions:
1) divide the page into more than one page
2) track key/button down and either ignore or pass the value captured.

Vinny

joeframbach
07-21-2003, 05:00 PM
you could just put up a <div> with a really high z-index...

beetle
07-21-2003, 05:09 PM
Or, optimize your loop. If you're using for, switch to a while loop. Store and use references.