Solved

chaning the innertext of a label with javascript

Posted on 2006-10-24
6
1,385 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
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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

696 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