Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamically setting className sets foreground text color incorrectly

Status
Not open for further replies.

willj49

Programmer
Jan 3, 2005
7
US
I am dynamically getting the value of an input element of type='password' in an HTML form reading its password, then creating a text input element and sticking it into that one to reveal the secret password. It works fine when I don't apply a CSS class name to the created text input element. But if I do then the foreground text is always invisible. If I click the text with my mouse and drag my cursor over it, to select the text then I can see the text. Then after clicking again to deselect the text, the text appears correctly with the appropriate style applied! If I set a specific foreground color for the text it has no effect to this behavior. The text is still invisible. If I set a specific background color, the background color works correctly and shows up immediately after I add the created text input element, but the foreground text color is always invisible until I mess with it by manually selecting some text and unselecting it.

Note: I am running in IE 6.

Here's my Javascript code:

var n = document.getElementById("PASSWORD_FIELD");
var elm = document.createElement('input');
elm.value = n.value;
elm.size = "11";
elm.type = "text";
elm.name = "PASSWORD_FIELD";
//This next line is what causes the weird behavior...
elm.className = "myStyleClass";

var parent = n.parentNode;
parent.removeChild(n);
parent.insertBefore(elm,parent.firstChild);

--
I've tried adding a foreground color and a background color to my style like this...
.myStyleClass {font-family:Verdana;font-size:10pt;color:FF0000;background-color:#6666CC;}

But the problem seems to happen no matter how I style this. The only way to avoid it that I can see, is to not set a style to the className attribute. But I'd like to be able to set a style.

I can't understand why this is happening or how to fix it. Any ideas or thoughts?

Thanks,
Will


 
I just noticed another factor in my situation. My password text is 9524 characters long. When I reduce the size of the password text to 10 it works fine. So apparently this is related to large amounts of text stored in the field.
 
LOL, well I'm not really sure how it ended up 9524 characters, the actual password wasn't really that long, I was encrypting the entered password with OpenPGP and then base64 encoding that. Normally this was causing a 12 character password to bloat out to about 500 characters or so, but it never should have been over 9000! I think maybe I had some bug that was causing the encrypted one to append several times and corrupted it. Anyway, I managed to reduce it and all is worked out now. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top