Solved

Javascript style enable/disable question

Posted on 2002-04-04
6
7,143 Views
Last Modified: 2011-10-03
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.
0
Comment
Question by:russomr
6 Comments
 
LVL 3

Expert Comment

by:winningl
ID: 6918543

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

winningl
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6918586
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
 
LVL 33

Accepted Solution

by:
knightEknight earned 20 total points
ID: 6918679
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 33

Expert Comment

by:knightEknight
ID: 6918680
... and in your enable function:

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

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 6918682
oops, in the enable function the className should be "enabled"
0
 

Author Comment

by:russomr
ID: 6919107
Didn't use this exactly, but your comment did give me the idea for an onfocus redirect I ended up using.  Thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now