473,397 Members | 1,985 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,397 software developers and data experts.

change HTML label on the fly

I want to change the label on the fly (when the user click the
checkbox), but my attempt
InputForm.lataLbl.value = "LATA * "; didn't work. Here's my code, any
ideas?
thanks !!!
<html>
<script type="text/javascript">
function ig_onchange()
{ if (InputForm.ig.checked == true)
{ InputForm.btn.value = "Populate";
InputForm.lataLbl.value = "LATA * "; //DOES NOT WORK!!!
}
else
{
InputForm.btn.value = "Validate";
}
}
</script>
<body>
<form name="InputForm">
<P><input type="checkbox" name="ig" onclick="ig_onchange()">
<P><label for="lataLbl">LATA</label>
<P><input type="button" name="btn" value="Validate">
</form>
</body>
</html>
Jul 23 '05 #1
3 26951
Voyez innerhtml

GR

Matt a écrit:
I want to change the label on the fly (when the user click the
checkbox), but my attempt
InputForm.lataLbl.value = "LATA * "; didn't work. Here's my code, any
ideas?
thanks !!!
<html>
<script type="text/javascript">
function ig_onchange()
{ if (InputForm.ig.checked == true)
{ InputForm.btn.value = "Populate";
InputForm.lataLbl.value = "LATA * "; //DOES NOT WORK!!!
}
else
{
InputForm.btn.value = "Validate";
}
}
</script>
<body>
<form name="InputForm">
<P><input type="checkbox" name="ig" onclick="ig_onchange()">
<P><label for="lataLbl">LATA</label>
<P><input type="button" name="btn" value="Validate">
</form>
</body>
</html>


Jul 23 '05 #2
jr********@hotmail.com (Matt) writes:
I want to change the label on the fly (when the user click the
checkbox), but my attempt
InputForm.lataLbl.value = "LATA * "; didn't work.
No, for many reasons.

First of all, referring to the form by using its name as a variable
won't work in most browsers (it will work in IE).

The label is not a form control, so it's not a property of the form.

The content of a label is normal HTML, so you can't refer to it
as a simple property named "value".
Here's my code, any ideas?


Try this:
---
<!DOCTYPE html PUBLIC "-//W3C/HTML 4.01//EN">
<html>
<title>Title element is required, as is DOCTYPE!</title>
<script type="text/javascript">
function ig_onchange() {
var form = document.forms['InputForm'].elements;
if (form.ig.checked) {
form.btn.value = "Populate";
document.getElementById("labelId").firstChild.node Value="LATA *";
} else {
form.btn.value = "Validate";
}
}
</script>
<body>
<form name="InputForm" id="InputForm">
<p><input type="checkbox" name="ig" onclick="ig_onchange()"></p>
<p><label id="labelId" for="buttonId">LATA</label></p>
<p><input type="button" id="buttonId" name="btn" value="Validate"></p>
</form>
</body>
</html>
---

It only works in modern browsers. There are a few older browser
(especially IE 4) that can be made to work with some extra code.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3
Don't multi post. It annoys the regulars when found out.

I just read this in alt.html.

Cross post if you must.

Jeff
"Matt" <jr********@hotmail.com> wrote in message
news:ba**************************@posting.google.c om...
I want to change the label on the fly (when the user click the
checkbox), but my attempt
InputForm.lataLbl.value = "LATA * "; didn't work. Here's my code, any
ideas?
thanks !!!
<html>
<script type="text/javascript">
function ig_onchange()
{ if (InputForm.ig.checked == true)
{ InputForm.btn.value = "Populate";
InputForm.lataLbl.value = "LATA * "; file://DOES NOT WORK!!!
}
else
{
InputForm.btn.value = "Validate";
}
}
</script>
<body>
<form name="InputForm">
<P><input type="checkbox" name="ig" onclick="ig_onchange()">
<P><label for="lataLbl">LATA</label>
<P><input type="button" name="btn" value="Validate">
</form>
</body>
</html>

Jul 23 '05 #4

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

Similar topics

2
by: knoak | last post by:
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:...
0
by: beanweed | last post by:
BACKGROUND ---------- I have an ASP.NET application having two panels. In one panel, an XML document, transformed using xsl, is displayed. In the other panel are some controls that allow a user...
7
by: David | last post by:
Hi, I'd really appreciate any help. Im trying to change a label over and over again. I can change it the first time, by using the following code, however it never works again, how can i do this...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
10
by: apparker | last post by:
I'm creating a new GUI for a program and it is for a medical exam. There are so many different things to ask someone during a history it wastes too much space to make checkboxes for everything so I...
0
by: imranabdulaziz | last post by:
Hi all, I am using asp.net2.0 and C# VS2005. I am creating asp.net web server control templates Dynamically . My requirement is such that sp return very no of field( 4 or 5 or 6 …). Now I am...
2
RedSunFlowers32
by: RedSunFlowers32 | last post by:
Hi - I am creating a form for my personal business site. I want people to be able to get their own shipping total for the item(s) they have purchased. I have another code from a different file I...
0
by: vincent90152900 | last post by:
I like to Customize the layout of a CreateUserWizard component and I would like to chnge the “Create User” button to an ImageButton. How to do that? Following is my codes. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.