This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to disable all form elements

 
Aravind JAI
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How To disable all form elements while clicking a button..
Thanks in Advance
 
Kj Reddy
Ranch Hand
Posts: 1704
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It gives error like, formNames is undefined..
 
Kj Reddy
Ranch Hand
Posts: 1704
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Very Much Friend..Can i have Your Mail-id
 
Aravind JAI
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again i am getting error message..document.forms is null or not an object
 
Kj Reddy
Ranch Hand
Posts: 1704
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks it is working fine..Please give ur mail id
 
Kj Reddy
Ranch Hand
Posts: 1704
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic