Changing label

C

Charlotte

Hello

I was wondering if anyone could tell me how i can change a label
dynamically with each click on the label??

Thanks

Charly
 
J

jojowebdev

I dont know.. but

...Well you gotta start breaking it down right?

So.. do you have any code?

I guess we need a label.

<label id='clickMe' onClick='callFunction();'>

<function clickMe() {
// code goes here
}

Does that get you started?
 
S

Sevinfooter

Very simply:

<html>
<head>
<script language = 'javascript'>

function changeLabelText(controlID)
{
var thisLabel = document.getElementById(controlID);
thisLabel.innerHTML = "Some Other Text";

}

</script>
</head>
<body>
<form>
<label for="radio1" id="radioLabel"
onclick="changeLabelText(this.id)">Some Text</label>
<input id="radio1" type="radio" />
</form>
</body>
</html>
 
R

Richard Cornford

Sevinfooter wrote:
function changeLabelText(controlID)
{
var thisLabel = document.getElementById(controlID);
<label for="radio1" id="radioLabel"
onclick="changeLabelText(this.id)">Some Text</label>

What is the rational of passing - this.id - and then using the ID
string passed with the - document.getElementById - method to look up a
reference to the LABEL element? Given that IDs must be unique within a
document and the - id - property of an element reflects its ID
attribute the element returned from document.getElemetnById must be the
same element as the - this - in - this.id -, so you may as well just
pass - this - and have the element reference in the function directly.
<input id="radio1" type="radio" />
<snip> ^

And why the pseudo XHTML mark-up in a document that could only be HTML?

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top