Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can CSS affect the readonly functionality of a text input box?

Status
Not open for further replies.

Einstein47

Programmer
Nov 29, 2001
737
US
I have a disagreement with another of our web developers. He feels that since we have a class defined in our global css file called &quot;readonly&quot; that it should be able to affect a <INPUT type=&quot;text&quot; ... > form element so that it cannot be modified. I told him that css can't do that and he would have to put the attribute &quot;readonly&quot; in the INPUT declaration.

Basically I do this:
Code:
<INPUT type=&quot;text&quot; name=&quot;field1&quot; class=&quot;readonly&quot; readonly value=&quot;<%=serverVariable%>&quot;>
Is the readonly attribute necessary, or is my co-worker correct that there is a way with CSS to affect that behavior? Einstein47
(&quot;The only reason I would take up exercise would be so I could hear heavy breathing again.&quot;)
 
Because you don't tell us what the CSS-class &quot;readonly&quot; is used for (and the code in that class), so it is hard to answer your question Is the readonly attribute necessary.

But I can answer you that, as far as I know, you can't affect a &quot;readonly&quot; with CSS.

But try this example, maybe you can use that then you don't have to add the attribute to all the tags and you can't make mistakes in your code:

<HTML>
<HEAD>
<TITLE></TITLE>

<script language=&quot;javascript&quot;>
function checkReadonly()
{

var Inputs = document.getElementsByTagName(&quot;INPUT&quot;);
total = Inputs.length

for (ia = 0; ia < total; ia++)
{
if (Inputs[ia].className == &quot;readonly&quot;)
{
Inputs[ia].disabled = true;
Inputs[ia].style.background = &quot;lightblue&quot;;
}
else
{
Inputs[ia].disabled = false;
Inputs[ia].style.background = &quot;white&quot;;
}
}
}

</script>
</HEAD>

<BODY onload=&quot;checkReadonly()&quot;>
<FORM>
<INPUT type=&quot;text&quot; name=&quot;field1&quot; class=&quot;readonly&quot;><br>
<INPUT type=&quot;text&quot; name=&quot;field2&quot; class=&quot;NOTreadonly&quot;><br>
<INPUT type=&quot;text&quot; name=&quot;field3&quot;><br>
</FORM>
</BODY>
</HTML>

hope this helps,
Erik


<-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top