473,624 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing the text color of an input element (IE)?????

My God, how on earth do you use javacript to change the text color of
an input element, and have it work with IE??? I've tried numerous
solutions. All of them work on browsers such as Mozilla. But none of
them work on IE.

This works in every browser I've tried besides IE:

var whatever = document.create Element( 'input' );
whatever.type = 'text';
// (more code)...
whatever.style. color = 'black';

This also works for other browsers besides IE:

whatever.style. cssText = 'color:black;';

I've tried other things as well. Nothing works in IE. Is there anyway
to change the text color inside an input box dynamically, and have it
work in IE? Can someone please help?

Thanks.

Jan 9 '07 #1
10 4319
sb********@aol. com wrote:

Hi,
My God, how on earth do you use javacript to change the text color of
an input element, and have it work with IE???
I'm not sure your god is reading this newsgroup, but let's try to answer
anyway :) You normally do it the the same way as with other browsers:
grab a reference to the INPUT element and update its color style
property. Also, note that style cascading rules would apply, so you
could lose the color initially set by CSS selectors.
whatever.style. color = 'black';
Using 'black' as a color to test whether the color is changed isn't very
appropriate since the default font color is normally black...
whatever.style. cssText = 'color:black;';
cssText is a property defined in the W3C DOM Styles specification. IE
does not support this specification but rather uses its own set of
objects and properties (in you want to know more about this, try
searching comp.lang.javas cript archives for cssRules, currentStyle and
getComputedStyl e).

Internet Explorer does have issues with dynamically created FORM
elements using DOM methods (e.g the NAME attribute not being set
correctly with radio buttons), however I wouldn't be able to tell what
goes wrong without some (trimmed) example code demonstrating the issue.

Try for yourself, in some blank document:

---
<body>
<script type="text/javascript">
var input=document. createElement(" input");
input.type="tex t";
input.style.bac kgroundColor="y ellow";
input.style.col or="red";
document.body.a ppendChild(inpu t);
</script>
</body>
---

HTH.
Jan 10 '07 #2
Doesn't work in IE (at least for me it doesn't). Any other ideas?

Try for yourself, in some blank document:

---
<body>
<script type="text/javascript">
var input=document. createElement(" input");
input.type="tex t";
input.style.bac kgroundColor="y ellow";
input.style.col or="red";
document.body.a ppendChild(inpu t);
</script>
</body>
---
Jan 10 '07 #3
sb********@aol. com said the following on 1/10/2007 10:17 AM:

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
>
>Try for yourself, in some blank document:

---
<body>
<script type="text/javascript">
var input=document. createElement(" input");
input.type="te xt";
input.style.ba ckgroundColor=" yellow";
input.style.co lor="red";
document.body. appendChild(inp ut);
</script>
</body>
Doesn't work in IE (at least for me it doesn't). Any other ideas?
Wrap the code in a function, call it onload, and it will create the
input (at least in IE7 it does)

function addInput(){
var input=document. createElement(" input");
input.type="tex t";
input.style.bac kgroundColor="y ellow";
input.style.col or="red";
document.body.a ppendChild(inpu t);
}
window.onload=a ddInput

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 10 '07 #4
sb********@aol. com wrote:
Doesn't work in IE (at least for me it doesn't). Any other ideas?
The code I have provided works as expected in IE5, IE5.5, IE6 and IE7 on
Windows XP SP2 (and of course, in Firefox 1.5 and Opera 9 as well). If
you have copied-pasted the code in some blank document (using standard
text editor) and that it still does not work, then I am afraid I won't
be able to help much more. Just to be sure: what platform are you
working on, what version of IE are you using?

@Randy: are you aware of some IE7 problem to process that kind of code
if not put in some load handler?
Regards,
Elegie.
Jan 10 '07 #5
Elegie said the following on 1/10/2007 10:51 AM:
sb********@aol. com wrote:
>Doesn't work in IE (at least for me it doesn't). Any other ideas?

The code I have provided works as expected in IE5, IE5.5, IE6 and IE7 on
Windows XP SP2 (and of course, in Firefox 1.5 and Opera 9 as well). If
you have copied-pasted the code in some blank document (using standard
text editor) and that it still does not work, then I am afraid I won't
be able to help much more. Just to be sure: what platform are you
working on, what version of IE are you using?

@Randy: are you aware of some IE7 problem to process that kind of code
if not put in some load handler?
I copy/pasted your exact code into a blank HTML4.01 Strict test document
and it wouldn't create the input in IE7. I thought maybe it wasn't
wanting to add it to the body so I tested it adding it to a form and it
still wouldn't. When I moved it into a function and called it onload of
the page it worked flawlessly adding it to an existing form. Then I
changed it back to your original code in a function, called it onload,
and it creates the input. I think it's more of a "IE won't add it since
the document isn't loaded completely" kind of thing but not positive.

How you can say you have it working in IE7 on XP SP2 is odd though as
that is exactly the platform I tested it on and it wouldn't create the
input without letting the document finish loading first.

Not sure "input" is a good name for the variable either.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 10 '07 #6
Randy Webb wrote:
Elegie said the following on 1/10/2007 10:51 AM:
<snip>
>The code I have provided works as expected in IE5, IE5.5, IE6 and IE7
on Windows XP SP2 (and of course, in Firefox 1.5 and Opera 9 as
well). ...

I copy/pasted your exact code into a blank HTML4.01 Strict test
document and it wouldn't create the input in IE7. ...
<snip>
How you can say you have it working in IE7 on XP SP2 is odd
though as that is exactly the platform I tested it on and it
wouldn't create the input without letting the document finish loading first.
The code as posted worked for me on IE 7.0.5730.11 (both literally, as
the entire document and replacing the body on a blank HTML 4.01 Strict
page) (on XP SP2).
Not sure "input" is a good name for the variable either.
Style-wise maybe not, mechanically it should be fine.

Richard.

Jan 10 '07 #7
Randy Webb wrote:

<snip>

(Thanks for the description of your tests!)
I think it's more of a "IE won't add it since
the document isn't loaded completely" kind of thing but not positive.
If so, this would IMHO be some serious flaw, the tree is supposed to be
live by nature, refusing to modify it while it is being built would be
an inappropriate vendor choice.
How you can say you have it working in IE7 on XP SP2 is odd though as
that is exactly the platform I tested it on and it wouldn't create the
input without letting the document finish loading first.
I have the same version as Richard (7.0.5730.11). I can only suppose
that either you have an older version, in which this was some bug, or
that you have some newer version, in which this is a feature.

I cannot imagine any other explanation at the moment (apart from some
mistake in my testing process, which I have however checked twice, and
which seems confirmed by Richard's results) :(
Not sure "input" is a good name for the variable either.
Nope, indeed, sorry. In the context of the test one might think that
there could be some not-so-unusual naming conflict, and in the context
of some program it is probably not appropriate as well (I'd use some
variable name describing the field if known, or the more generic
"control" or "inputContr ol" if in a generic process, but that's just a
personal taste).
Regards,
Elegie.
Jan 10 '07 #8
Elegie said the following on 1/10/2007 12:58 PM:
Randy Webb wrote:
<snip>
>How you can say you have it working in IE7 on XP SP2 is odd though as
that is exactly the platform I tested it on and it wouldn't create the
input without letting the document finish loading first.

I have the same version as Richard (7.0.5730.11). I can only suppose
that either you have an older version, in which this was some bug, or
that you have some newer version, in which this is a feature.

I cannot imagine any other explanation at the moment (apart from some
mistake in my testing process, which I have however checked twice, and
which seems confirmed by Richard's results) :(
I just checked mine and it is also 7.0.5730.11 so I am not sure. I
rechecked the code again and it still doesn't work for me. Odd to say
the least.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 10 '07 #9
Randy Webb wrote:
I just checked mine and it is also 7.0.5730.11 so I am not sure. I
rechecked the code again and it still doesn't work for me. Odd to say
the least.
Could you have a user stylesheet that overrides any styles set in the
source?

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jan 10 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2725
by: multimatum2 | last post by:
Hello, I need to enable/disable input text forms... But... I need to have the same style (color...) in both modes.. Could you help me ? Thanx a lot A small sample... <HTML><HEAD><TITLE></TITLE></HEAD>
8
3164
by: Margaret MacDonald | last post by:
I'm a js novice trying to teach myself. I'm using Flanagan's 'Javascript, the definitive guide' from O'Reilly as a text. But either I'm dopier than usual or its layout doesn't match my learning style very well, because I seem to be having a dreadful time getting to grips with even the simplest things. Currently, I'm trying to change the text that follows a <p> element in a little test program. My test program has a table with two <td>...
8
3348
by: horos | last post by:
hey all, Ok, a related question to my previous one on data dumpers for postscript. In the process of putting a form together, I'm using a lot of placeholder variables that I really don't care about in the submitted action. I'd therefore like to get rid of them by doing something like:
7
6053
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is there any other way to display/undisplay parts of web pages? TIA
5
2991
by: simon_s_li | last post by:
Hi, I have 5 fields in line where I need to drag and drop the text from one field to another field and then all the fields need to re-order themselves. So for instance if I drag the text in field 1 to field 3, then field 2 text and field 3 move to field 1 and field 2. I add the new order of text into an array so when the onDragEnd event
5
2098
by: cjl | last post by:
Hey all: This code: if (stealth) { document.searchme.query.type = 'password'; } else {
2
55299
by: yawnmoth | last post by:
Say I have two input elements and that I wanted to make it so that when the first ones input was what it should be, the focus would automatically be shifted to the next input element. ie. something like... <input onkeyup="if (this.value.length == this.maxlength) document.forms.elements.focus()" value="whatever" maxvalue="x" type="text" /> <input value="whatever" maxvalue="x" type="text" />
1
4191
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being aligned to the top, along with the slideshow and link buttons, you have to scroll down to see the text - how can I make IE6 display correctly? http://geekarama.co.uk/new_home.html here is the code for new_home.html and following that the CSS...
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.