Connecting Tech Pros Worldwide Forums | Help | Site Map

change HTML label on the fly

Matt
Guest
 
Posts: n/a
#1: Jul 23 '05
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>

G Roydor
Guest
 
Posts: n/a
#2: Jul 23 '05

re: change HTML label on the fly


Voyez innerhtml

GR

Matt a écrit:[color=blue]
> 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>[/color]

Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#3: Jul 23 '05

re: change HTML label on the fly


jrefactors@hotmail.com (Matt) writes:
[color=blue]
> 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.[/color]

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".
[color=blue]
> Here's my code, any ideas?[/color]

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 - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jeff Thies
Guest
 
Posts: n/a
#4: Jul 23 '05

re: change HTML label on the fly


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" <jrefactors@hotmail.com> wrote in message
news:ba8a039e.0406251026.68e1e19c@posting.google.c om...[color=blue]
> 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>[/color]


Closed Thread