Javascript style enable/disable question

The question titled

'Using Javascript to disable/enable form fields qui...'

explains the use of a style to transform the background color of a text box on a disable/enable function.  Is there anyway to transform the color of the text as opposed to the background?  My code is as follows:


     --Style sheet code--
<style>
.disabled { color: red; }
.enabled  { color: #000000; }
</style>

     --Javascript code--
document.form1.time41.className = "disabled";
document.form1.time41.disabled  = true;


It works fine when I replace 'color:' with 'background-color:'.  I'm trying to alter the color of the text though.  Any help is greatly appreciated.
russomrAsked:
Who is Participating?
 
knightEknightConnect With a Mentor Commented:
try this ... first make a global variable:

<SCRIPT>
var time41disabled = false;
</script>


... then in your function:


document.form1.time41.className = "disabled";
//document.form1.time41.disabled = false;
time41disabled = true;


... then in your textbox:


<INPUT name="time41" onFocus="if(time41disabled)this.blur();">
0
 
winninglCommented:

I think disabled and enabled are reserved words. Try rename the class name to something else.

winningl
0
 
COBOLdinosaurCommented:
The problem is you are setting disabled tp true.  That overrides the text color because the behaviour of the disabled property is to gray the text.  You can't do both.  Either change the color or set disabled to true.

Cd&
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
knightEknightCommented:
... and in your enable function:

document.form1.time41.className = "disabled";
time41disabled = false;

0
 
knightEknightCommented:
oops, in the enable function the className should be "enabled"
0
 
russomrAuthor Commented:
Didn't use this exactly, but your comment did give me the idea for an onfocus redirect I ended up using.  Thanks.
0
All Courses

From novice to tech pro — start learning today.