Jump to content

Disable Input Field


kvnmck18

Recommended Posts

How do you "lock" and input field in a form? So it can't be edited, but you can see the intial/default value.

Link to comment
Share on other sites

you can do this <input type="text" readonly="readonly".../> or use JSvar field = document.getElementById('fieldId');field.disabled = true;The JS method will "gray out" the field similar to Windows Forms.

Link to comment
Share on other sites

(A little clarification below.)You can either use the readonly attribute or the disabled attribute:<input type="text" readonly="readonly" ...<input type="text" disabled="disabled" ...The difference is that the disabled attribute will gray out the text field while the readonly attribute will not. On Firefox, the text in a disabled text field cannot be selected and copied to the clipboard.You can also use JavaScript to set the readonly or disabled attribute:var field = document.getElementById('fieldId');field.readOnly = true;var field = document.getElementById('fieldId');field.disabled = true;

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...