473,503 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14386
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
986
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
2079
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
9133
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
12623
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
5856
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
2817
by: zion | last post by:
Hello, How can I change label caption on page load ? Thanks
3
4843
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
4350
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
13811
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
7202
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,...
0
7086
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...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
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...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1512
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 ...
1
736
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.