Set readonly in input field

I have a text input field (called "buyAmount") in a form. When the Submit button is clicked, I want to set the field to readonly, so that the user will not be able to change anything. This is how I do it in Javascript:

var ba = document.getElementById("buyAmount");
ba.readonly = true;
frm.submit();

Somehow the readonly is not working. The user can still change the value. I can't do a "ba.disabled = true" as it will prevent the value from being sent.

Any ideas? Thanks.
LVL 9
yongsingAsked:
Who is Participating?
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.

RoonaanCommented:
Hi,

The readonly property should do the trick. Are you sure you got the right element?

-r-
0
Sys_ProgCommented:
Hi yongsing,
I am not sure if I understood you correctly.

You said you want to make the field readonly when the form is submitted.
Thus, the user will be able to anyways change any value in it before the form is submitted
You should make the field readonly when the form is loaded (while defiing the field) so that the user cannot edit it

Cheers!
0
KennyTMCommented:
Hi.

Note the capitalization: it is "readOnly", not "readonly".
0

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GawaiCommented:
<input name=buyAmountvalue=somevaluefromDB readonly>
0
GawaiCommented:
sori for the previous post try this one
<input name=buyAmount value=somevaluefromDB readonly>
0
raj3060Commented:
This should work:

ba.readOnly = true;
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.