Js to toggle readonly/disabled and value of form button

Hey all,

  I have a form that I want the user to be able to click a button, then a form field becomes editable, and the button they clicked changes from saying Edit to Apply


function expenseToggle() {

    if (this.form1.submit.value == "Edit") {
        this.form1.submit.value == "Apply";
        this.form1.AcctDist.disabled == False;
    }
   else {
       this.form1.submit.value == "Edit";
       this.form1.AcctDist.disabled == true;
    }
}



form1:
<input value="" name="eAcctDist" disabled>
<input  value="Edit" type="submit" name="submit" OnClick="expenseToggle()">

when I run this code, nothing even happens in FF, and IE the page refreshes faster than I can see the error.


DigitalFusionTomAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MaartenHensenCommented:
Something like this?
<form id="myForm">
	<input id="eAcctDist" value="" name="eAcctDist" disabled>
	<input id="action" value="Edit" type="button" OnClick="expenseToggle(this)">
</form>

<script>
	function expenseToggle() {

		if ( myForm.action.value == "Edit") {
			myForm.action.value = "Apply";
			myForm.eAcctDist.disabled = false;
		} else {
		   myForm.action.value = "Edit";
		   myForm.eAcctDist.disabled = true;
		}
	} 
</script>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DigitalFusionTomAuthor Commented:
thanks for the post.  


using the code u posted, I get no errors in IE or FF, but nothin happens when I click the "edit" button.  
MaartenHensenCommented:
If you create a page with just this code it should work ( thats how i tested in the latest version of Chrome & Firefox ).

Please note that I changed the name of the form & the type of the button.
DigitalFusionTomAuthor Commented:
hmm, your right...

DigitalFusionTomAuthor Commented:
however, I need the button to be a type of submit after clicking apply so the server can process the input.  I might have to look into doing this a different way.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.