JonathanLaker
JonathanLaker

Reputation: 303

Is there a way for me to make an <input> field non-editable

I have some fields that are currently input fields. Some should allow edits and others not. Without changing them from input fields, is there a simple way to make it so I cannot edit these? I'm looking for just one CSS or other kind of property if that exists.

thanks

Mariko

Upvotes: 2

Views: 5958

Answers (4)

Faraz Kelhini
Faraz Kelhini

Reputation: 3985

either

<textarea ... readonly="readonly"></textarea>

and/or :

<textarea ... disabled="true"></textarea>

I prefer readonly -attribute, which just prevents modifying. Disabled attribute makes the whole area look disabled (grey) and disabled textarea's data isn't submitted, when a form is posted.

Upvotes: 1

Varada
Varada

Reputation: 17034

<input type="text" id="id" name="id" value="" readonly="readonly" />

Upvotes: 1

Rudie
Rudie

Reputation: 53781

Or disabled: <input disabled>

You can style both with CSS:

input:disabled or input[disabled] for disabled

input[readonly] for readonly

Upvotes: 4

fin1te
fin1te

Reputation: 4351

You can add the readonly="readonly" attribute to the input elements.

Upvotes: 9

Related Questions