Jump to content

form submit and disabled fields


george

Recommended Posts

I have a form which prior to loading get data from datasource. The fields with data are disabled. The user inputs data in new fields, and then clicks submit. All the old data is lost. It behaves as though a disabled field is automatically rendered null. I have tried to fashion a submit button that would call a JS function first to enable all the fields. This did not work. Then I sought to create my own submit button, but couldn't find the DOM method to submit. Is there some work around to this? I want the data that was pulled for a record, and displayed in a disabled field, to be returned to the record upon submit. Help!! :)

Link to comment
Share on other sites

The DOM property to enable/diasable a form input is ".disabled" and the DOM method to submit a form is ".submit()".You could have a function similar to this:

function enableElements(formObj){	var formElements = formObj.elements;	for(var i = 0; i < formElements.length; i++)	{		formElements[i].disabled = false;	}}

And you could call it on the submit event of your form:

<form id="myForm" action="myAction.php" method="POST" onsubmit="enableElements(this);">

EDIT: Alternatively, you could store the data in hidden inputs. Both of these methods, however, can be circumvented by savvy users. The most secure method would be to check the fields on the server when the form was submitted. If there are values in the database for certain fields, then the values submitted with the form could be ignored.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...