Sachindra
Sachindra

Reputation: 6969

making text boxes non editable in html

i am trying to make a text box no editable for the users. I tried using this code and it works. Any ramifications??? I mean do u suggest the use of this code or it may cause trouble for me in future???

<input type="text" name="west" value="fixed value" readonly />

Upvotes: 0

Views: 10716

Answers (2)

skyfoot
skyfoot

Reputation: 20769

you shouldnt have a problem with this code as the inputs value gets submitted along with any other inputs in the form.

Make sure that you validate this on the server side as someone could send a value you are not expecting via dev tools or tools like fiddler.

I would change it to have a value. e.g readonly="readonly" so that it is valid xhtml. The value of the readonly attribute is irrelevant and can therefore be any value.

All of the below are readonly

<input type="text" readonly="readonly" value="readonly" />
<input type="text" readonly="true"  value="true" />
<input type="text" readonly="monkey" value="monkey" />
<input type="text" readonly="false" value="false (still readonly)" />

input documentation

Upvotes: 6

greg0ire
greg0ire

Reputation: 23255

You must be aware that anybody can change this to something writable using a tool like firebug.

Upvotes: 3

Related Questions