Solved

Javascript style enable/disable question

Posted on 2002-04-04
6
7,167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…
Suggested Courses

624 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