[X]HTML HowTo: Disable a text box.

Good afternoon!

I figured I would start posting some minor tutorials on how to do some of the less common things with [X]HTML.

As the title denotes, today’s tutorial is on disabling* access to a text box. The code is simple enough, and can be found below:

disabled="disabled"

And, using it within the context of a form:

<input type="textbox" name="name_of_choice" id="id_of_choice" disabled="disabled" />

And, there you have it. Your text box is disabled, and the user will not be able to change the value of the text box within the browser.

*For added security, do server-side form validation to make sure the value has not changed. Or, if you really want information to be unchanged, do not put the information within a text box, but rather print it to the screen.

Nick

Leave a Reply