473,372 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Change all label appearances

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.getElementById(label);
if (label && label.style) {
label.style.color = '#A2A2A2';
};
=======================================

So reset will have onClick="GrayLabels()" 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
Jul 23 '05 #1
2 14378
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.getElementById(label);
if (label && label.style) {
label.style.color = '#A2A2A2';
};
=======================================

So reset will have onClick="GrayLabels()" 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(labelColor) {
if (document.getElementsByTagName) {
var labels = document.getElementsByTagName('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">THREE</label>
<br>
<button onclick="setLabelColor('Gray');">Make Gray</button>
<button onclick="setLabelColor('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('yourPrefix') == 0) {

labels[i].style.color = labelColor;
}

--
| Grant Wagner <gw*****@agricoreunited.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
Jul 23 '05 #2
knoak wrote:
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.


You need to retrieve the collection of all LABEL elements.

W3C DOM:
document.getElementsByTagName("label")

IE4 DOM:
document.all.tags("label")

NS4 DOM:
document.layers[number] if the elements are positioned

Then iterate through the collection. Assign the empty string ("") to
the respective CSS property to assign the initial value after all CSS
rules have been rendered:

var coll = null;

if (document.getElementsByTagName) // W3C DOM
{
coll = document.getElementsByTagName("label");
}
else if (document.all && document.all.tags) // IE4 DOM
{
coll = document.all.tags("label");
}

if (coll && coll.length)
{
for (var i = 0, len = collection.length; i < len; i++)
{
if ((o = collection[i].style) && typeof o.color != undefined)
{
o.color = "";
}
}
}
PointedEars
Jul 23 '05 #3

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

Similar topics

0
by: Shapper | last post by:
Hello, I have a multilanguage web site. In a contact form I have a few labels. Something like: Subject: <Input Box> CODE: <label for="subject">Subject:<input type="text"
2
by: Sjaakie Helderhorst | last post by:
Hi there, I created my own user control (myControl) containing: myCaption - docked top myGrid - docked.fill (datasource: myDataset) myPanel - docked bottom This control is added to the form:...
6
by: Roger Ries via DotNetMonster.com | last post by:
I'm trying to change the text in a label from another form. lblInfo.Text = "ABC" Works for the form your currently in but how the heck do you change that label information from another form. ...
5
by: Luis Ramos | last post by:
Hello, How do i change a label in another form from another one? in vb6 i use to do this: form1: private sub label1_change() form2.label1.caption="hgghjghjg" ' and the label in form2 is...
4
by: Henrootje | last post by:
I have a REPORT with in it a subFORM Now I have this label (lblMonth) that I want to change. How should I do this? What would be the proper event to do this? The lblMonth should contain the...
1
by: zion | last post by:
Hello, How can I change label caption on page load ? Thanks
3
by: crjunk | last post by:
Hi Everyone, I have a web form that I would like to enhance. What I'd like to do is this: A user adds/edits the text in a textbox. I want the adjoining label to change color. Example: User...
3
by: saskoPython | last post by:
Hello, I go thrugh number of tutorials and steel can't find one simple thing (or I can't understand how to do this). My question is this: if we make "any" function like this: def myfunc():...
5
by: yappy77 | last post by:
I am trying to change the label color of a checkbox on a subform if it is checked. The code I have so far is: Private Sub Emergency_Contact_Click() If Me.Emergency Contact = True Then...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.