Solved

chaning the innertext of a label with javascript

Posted on 2006-10-24
6
1,352 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 120
mapAB Challlenge 35 124
Looking for example pivot year code used in Y2K 4 61
Scripting vs. Programming languages 25 151
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now