Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Read-Only Fields - Displaying as Disabled - CSS

RSS
Modified on Thu, Jul 21, 2011, 1:53 PM by Administrator Categorized as HTML and CSS
To style read-only fields to look like they're disabled, use the following CSS.

{copytext|css}
input[readonly] {
    color: graytext;
    background: buttonface;
}

In addition, because the READONLY attribute doesn't apply to SELECT elements, they can be "locked" via some jQuery in their ONCHANGE attribute, as follows.

<select onchange='$(this).val(original-value);'>
    <option . . . />
</select>

In Razor syntax, it might look like the following.

@Html.DropDownListFor(
    m => m.OrderTypeId, 
    new SelectList(Model.OrderTypes, "Id", "DisplayName"),
    new { @readonly="readonly", OnChange = "$(this).val(" + @Model.OrderTypeId + ");" }
    )

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2018, Patrick Jasinski.