View Full Version : Disable all form elements
03-02-2003, 06:30 PM
I have a form that is populated from a database. To prevent the data from being resubmitted, I want to disable every single form element so that the complete form is read only. If any of the data needs editing and resubmitting, an edit button needs to be clicked on to enable all form elements for editing.
Does anyone have a script that will cycle through all form element types (irrespective of their 'names', 'id's', etc) to disable/enable enmasse?
03-02-2003, 07:16 PM
03-24-2003, 07:30 AM
Thanks for the code you sent, it works a treat. I triggered it via an on-load and called it as a function from a button. All worked.
I then tried to enable the form elements by calling a function from outside the form (but on the same page), as follows:
This did not work. What am I failing to understand about this script?
03-24-2003, 07:48 AM
shouldn't it be:
and to make a single function to enable/disable elements:
//flag = true if disabled, false if enabled
var f = document.formname;
03-24-2003, 08:17 AM
Thanks, I'll try it out now.
How do you guys do this so fast? It takes me hours sorting out these things.
03-24-2003, 08:00 PM
Using elements is more proper.
I'd do it like this anyway
for( var elem, i = 0; ( elem = document.formname.elements[i] ); i++ )
elem.disabled = false ;
02-04-2005, 06:43 PM
I want to have an HTML form that depending on which radio button the user selects, different sets of form inputs are enabled. That is, one set of inputs (checkboxes and text input fields) are enabled when option 1 is selected, a second set is enabled when option 2 is selected, etc.
I searched the web and forums for this, but all I found was ways to disable/enable the entire form, not a subset of all the elements on the form. I think that the FIELDSET property could help me, but there is no LENGTH attribute for it. Any suggestions?
Puffin the Erb
02-04-2005, 08:38 PM
They will be able to submit data maliciously / accidentally.
Make sure this will not be a mission-critical problem - if so carry out further validation server-side.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.