Set readOnly color same as disabled color

I have a text field, and I use javascript to set its "readOnly" attribute to true dynamically. The text color is still black. Is it possible to make this color the same as when the "disabled" attribute is set to true, which is grey? Thanks.
LVL 9
yongsingAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
thirdConnect With a Mentor Commented:
try,

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Author: Third Santor</title>
<script>
  function toggle(obj, flag){
    obj.txt1.readOnly = flag;
    obj.txt1.style.color = flag?'#999999':'#000000';
  }
</script>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<form name="form1" method=post action="" onsubmit="">
<input type="text" name="txt2" value="disabled text" disabled>
<input type="text" name="txt1" value="sample text">

<input type="checkbox" name="chk" onclick="toggle(this.form, this.checked)">Read Only
</form>
</body>
</html>
0
 
KennyTMCommented:
set:

[textfield].style.color = "GrayText";
0
All Courses

From novice to tech pro — start learning today.