Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 18006
  • Last Modified:

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.
0
yongsing
Asked:
yongsing
1 Solution
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now