TRY AND ERROR

気になったこと、勉強したこと、その他雑記など色々メモしていきます。。Sometimes these posts will be written in English.,

In the HTML5, "readonly" attribute just works for text fields.

In the HTML5, "readonly" attribute just works for text fields like <input type="text"> or <textarea>...
I didn't know about that!

For example, in the case of to put an select tag.

Like this, it doesn't work as you think. It is editable.

<select readonly>
    <option value="v1">v1</option>
    <option value="v2">v2</option>
    <option value="v3">v3</option>
</select>


If you set a "disabled" attribute Instead of "readonly", It seems to be correct but you cannot receive this in server side when you submitted. So it doesn't work too.

<select disabled>
    <option value="v1">v1</option>
    <option selected value="v2">v2</option>
    <option value="v3">v3</option>
</select>


For result, If you want to make a not editable "select" tag, you should set a "disabled" attribute to child items but the selected one.
This works as not editable and could receive in server side.

<select>
    <option disabled value="v1">v1</option>
    <option selected value="v2">v2</option>
    <option disabled value="v3">v3</option>
</select>


Hmm...I feel It is a little technically.