473,911 Members | 5,861 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.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
Jul 23 '05 #1
2 14411
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
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.getEle mentsByTagName( "label")

IE4 DOM:
document.all.ta gs("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.getEl ementsByTagName ) // W3C DOM
{
coll = document.getEle mentsByTagName( "label");
}
else if (document.all && document.all.ta gs) // IE4 DOM
{
coll = document.all.ta gs("label");
}

if (coll && coll.length)
{
for (var i = 0, len = collection.leng th; 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
1006
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
2093
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: form1.controls.add(myControl) I wish to change label-value on myPanel whenever a value of myDataset has changed (by editing the grid). Since dataset.onchange doesn't exists, what
6
9176
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. Later --
5
12706
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 changed by the value i wanted end sub
4
5895
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 name of the month as jan 07 Any ideas?
1
2829
by: zion | last post by:
Hello, How can I change label caption on page load ? Thanks
3
4869
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 edits text in txtCaseNumber. The cursor leaves txtCaseNumber. Code executes and turns lblCaseNumber text from black to red.
3
4368
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(): #code here: return
5
13859
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 Me.Label23.BackColor = vbYellow Me.Label23.BackStyle = 1 Else Me.Label23.ForeColor = RGB(0, 0, 0)
0
9879
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11349
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11057
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10541
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5940
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6142
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4776
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 we have to send another system
2
4341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3360
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.