Solved

Javascript style enable/disable question

Posted on 2002-04-04
6
7,147 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now