...

View Full Version : Get input text background color?



knguyen99
08-23-2002, 10:18 PM
How do I get and check the input text background color?

ConfusedOfLife
08-23-2002, 10:35 PM
<html>
<head>
<title>Untitled</title>
<script>
function Report()
{
alert(document.getElementById("test").style.backgroundColor);
}
</script>
</head>

<body>

<input id="test" type="Text" value="" style="background-Color : green">
<input type="Button" value="Report!" onclick="Report();">

</body>
</html>

knguyen99
08-23-2002, 10:51 PM
I used the style sheet with class="text_required", is it make a difference?



<html>
<head>
<Title>Test Me</title>
<link rel="stylesheet" href="edge_1.css" type="text/css">
</head>
<body>
<table>
<tr>
<td>
<input id="test1" name="test" size=45 class="text_required" value="" />
</td>
</tr>
</table>
</body>
</html>

In the stylesheet edge_1.css file where:

input.text_required {type:text; height:19px; font-family:"Arial"; font-size:8pt; font-color:"black"; background-color:#c0dcc0; }

ConfusedOfLife
08-25-2002, 11:57 PM
Well, writing in an external file should be equal to writing for example inside the tag, and as you know the priority, I mean at first the internal, then the outer and then the external CSS will be excecuted, but in some cases as I experienced ( and I don't know why?! ) for changing a CSS value with java script or for seeing that, you have to write it as an internal value, in the code that you wrote, it perfectly works if you try to change the color by the following command :

<script>
document.getElementById("test1").style.backgroundColor = "#ff0000";
</script>

But if you try to see the current bgcolor, by alerting the value in the left side of the above line, you will see a null alert window! that I don't know why, and as I said, if you wrote at least the background-color inside the "input" tag, you could have seen that in here.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum