/    Sign up×
Community /Pin to ProfileBookmark

disable text box

i want to disable text box and display the text value as red color and when i enable the same text box, display the text value as blue color.

can someone help me with the code on how to do this?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 15.2007 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>disabled</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
function toggle() {
obj=document.getElementById('textBox');
if(obj.disabled) {
obj.disabled=false;
obj.style.color='blue';
}
else {
obj.disabled=true;
obj.style.color='red'; // can not be changed in IE, always grey
}
}
</script>

</head>
<body>
<div>
<input type="text" id="textBox" value="some text"><button type="button" onclick="toggle();">toggle</button>
</div>
</body>
</html>
Copy linkTweet thisAlerts:
@dabears60090authorSep 17.2007 — thanks Fang. actually, it is when the control is disabled that i wanted to display a different color. having it gray when disabled makes it hard to read and my user asked me if i can display it in a more 'visible' color.

so for i.e. i don't have any choice?
Copy linkTweet thisAlerts:
@FangSep 17.2007 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>disabled</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
function toggle() {
obj=document.getElementById('textBox');
if(obj.onfocus!=null) {
obj.onfocus=null;
obj.style.color='blue';
}
else {
obj.onfocus=obj.blur;
obj.style.color='red';
}
}
</script>

</head>
<body>
<div>
<input type="text" id="textBox" value="some text"><button type="button" onclick="toggle();">toggle</button>
</div>
</body>
</html>
Copy linkTweet thisAlerts:
@dabears60090authorSep 17.2007 — still, for disabled textbox, the text color will always be gray? i can't set it to any other color? ?

thanks again Fang.
Copy linkTweet thisAlerts:
@FangSep 17.2007 — In IE with [I]disabled[/I], gray is all you get.
×

Success!

Help @dabears60090 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...