aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to disable all  form elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to disable all  form elements" Watch "How to disable all  form elements" New topic
Author

How to disable all form elements

Aravind JAI
Greenhorn

Joined: Feb 06, 2006
Posts: 18
How To disable all form elements while clicking a button..
Thanks in Advance
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
Originally posted by Aravind JAI:
How To disable all form elements while clicking a button..
Thanks in Advance


Try this function:

function disable() {
for(var i=0; i<formnames.length;i++) {
formElements = formnames[i].elements;
for(var j=0; j<formElements.length;j++) {
document.formnames[i].formElements[j].disabled = true;
}
}
}

And call this function onclick of button.
Aravind JAI
Greenhorn

Joined: Feb 06, 2006
Posts: 18
It gives error like, formNames is undefined..
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
Sorry I missed few things.


Can you try this function:

function disable() {
var formnames = document.forms;
var formElements = new Array();

for(var i=0; i<formnames.length;i++) {
formElements = formnames[i].elements;
for(var j=0; j<formElements.length;j++) {
document.formnames[i].formElements[j].disabled = true;
}
}
}

And call this function onclick of button.
Aravind JAI
Greenhorn

Joined: Feb 06, 2006
Posts: 18
Thank You Very Much Friend..Can i have Your Mail-id
Aravind JAI
Greenhorn

Joined: Feb 06, 2006
Posts: 18
Again i am getting error message..document.forms is null or not an object
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
Try this simple function

function disablefunction() {
for(var i=0; i<document.forms[0].length;i++) {
document.forms[0].elements[i].disabled = true;
}
}
Aravind JAI
Greenhorn

Joined: Feb 06, 2006
Posts: 18
Thanks it is working fine..Please give ur mail id
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
Originally posted by Aravind JAI:
Thanks it is working fine..Please give ur mail id


The above solutions also should work with minor changes. They are most generic solutions. I will send you a PM with my email id.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
http://radio.javaranch.com/pascarello/2005/05/17/1116340367337.html

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to disable all form elements