Link to home
Start Free TrialLog in
Avatar of IDEASDesign
IDEASDesign

asked on

Form Button won't re-enable after having been disabled via onClick

I'm using a regular button (instead of a submit button) to submit my form.  

The button triggers a javascript function onClick that initiates a required field checking routine, which either prompts the user about missing required fields, .. or submits the form.

In addition to the required field checking script being triggered onClick, I am also disabling the button (to prevent multiple clicks).  My button code is as follows:

<input name="process" id="process" type="button" value="Process Order" onClick="check(myform,myform.elements.length);document.getElementById('process').disabled = true;" style="cursor:pointer;" />

My form has the name "myform" as well as the id value of "myform"

The button DOES become disabled when clicked - that part is no problem.
But I was thinking that I could update my required field checking javascript (stored in an external JS file) to re-enable the button if users get prompted about missing required fields:

document.getElementById('process').disabled = false;

(I have this line right above the javascript alert message that prompts the user)

Well it's NOT working.  

The button in the form remains disabled after the user clicks on the "OK" button in the alert dialog.  
The behavior is the same in both Firefox 2 and IE7.  

I've tried to add onSubmit="document.getElementById('process').disabled = false;" to the form tag, .. thinking that this would be the most logical approach.  But that doesn't seem to work either.  

How can I achieve this effect?  Ideally, I'd like a solution that doens't require me to modify my JS file for the required field checking.  Any tips or advice would be appreciated.

Thanks,
- Yvan


Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

perhaps you can have 2 graphic images, one represents "Enable" state, another represents "Disable" state. So when you click on the image, just swap the image accordingly.

I hope this makes sense.
ASKER CERTIFIED SOLUTION
Avatar of cLFlaVA
cLFlaVA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IDEASDesign
IDEASDesign

ASKER

Thanks cLFlaVA - that did the trick!.  

- Yvan