Solved

Javascript style enable/disable question

Posted on 2002-04-04
6
7,163 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

751 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