?
Solved

chaning the innertext of a label with javascript

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


Ta,


Ross
0
Comment
Question by:roscoeh23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Assisted Solution

by:daohailam
daohailam earned 1000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 41

Accepted Solution

by:
HonorGod earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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…
Introduction to Processes
Starting up a Project
Suggested Courses

752 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