knoak wrote:
Hi there,
In my form, after validation, labels of wrong
fields are turned into a red color.
What i want now is when you hit 'reset', to make all
the labels grey again.
I have the next code:
=============== =============== ========
function GrayLabels()
{
var label;
label = document.getEle mentById(label) ;
if (label && label.style) {
label.style.col or = '#A2A2A2';
};
=============== =============== =========
So reset will have onClick="GrayLa bels()" in it. But how
do i automatically apply this to everey label in the document?
Hope this is clear enough and thanks in advance..
Greetings
Assuming you truly mean _every_ label in the document, you could
use:
<script type="text/javascript">
function setLabelColor(l abelColor) {
if (document.getEl ementsByTagName ) {
var labels = document.getEle mentsByTagName( 'label');
if (labels) {
for (var i = 0; i < labels.length; i++) {
if (labels[i] && labels[i].style) {
labels[i].style.color = labelColor;
}
}
}
}
}
</script>
<label id="one">ONE</label>
<label id="two">TWO</label>
<label id="three">THRE E</label>
<br>
<button onclick="setLab elColor('Gray') ;">Make Gray</button>
<button onclick="setLab elColor('Black' );">Make Black</button>
If you only want specific labels, you could set their ID to a
specific prefix, then retrieve all labels and ignore those without
the prefix:
if (labels[i] && labels[i].style &&
labels[i].id.indexOf('yo urPrefix') == 0) {
labels[i].style.color = labelColor;
}
--
| Grant Wagner <gw*****@agrico reunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available
at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html