Solved

chaning the innertext of a label with javascript

Posted on 2006-10-24
6
1,375 Views
Last Modified: 2011-04-14
have tried and cannot seem to get this right.


Ta,


Ross
0
Comment
Question by:roscoeh23
  • 3
  • 2
6 Comments
 
LVL 5

Assisted Solution

by:daohailam
daohailam earned 250 total points
ID: 17795987
Use innerHTML instead:

document.getElementById('id_of_label').innerHTML = 'some text';
0
 

Author Comment

by:roscoeh23
ID: 17796042
my javscript is not great

why does this not work


<script>
document.getElementById('Label').innerHTML = 'some text';
</script>

<label id="Label"></label>
0
 
LVL 5

Expert Comment

by:daohailam
ID: 17796093
You script was activated before the page ready. So, the label with id "Label" may not exist at the time.  Work around solution is move the block '<script>...</script>' after <label>...</label>.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 41

Accepted Solution

by:
HonorGod earned 250 total points
ID: 17796381
or to invoke it some time after the page has loaded completely.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Label Modification </title>
<script type='text/javascript'>
  function change( obj ) {
    if ( obj ) {
      obj.value = 'New value';
    }
  }
</script>
</head>
<body>
<input type='button' value='Some value' onclick='change(this)' />
</body>
</html>
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17796426
or is this what you wanted?
--------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Label Modification </title>
<script type='text/javascript'>
  function change( id ) {
    if ( id && document.getElementById ) {
      var item = document.getElementById( id );
      item.innerHTML = 'Modified Label';
    }
  }
</script>
</head>
<body>
<label id='name' for='item'>Some label</label>
<input id='item' type='button' value='Some value' onclick='change("name")' />
</body>
</html>
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17805749
Thanks for the 'A'
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question