Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Browsers / Internet Explorer / September 2003



Tip: Looking for answers? Try searching our database.

LABEL tag

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul E. - 29 Sep 2003 16:32 GMT
Hello:

Could someone tell me how I can programatically
(JScript/DHTML) change the value of a Label tag?

For example, this is the HTML code:

<FORM name="myForm">
<LABEL for="myformfield">LabelValue</LABEL>
....
</FORM>

What is the code necessary to change the "LabelValue"
variable?

Thank you for any assistance you can provide.

- Paul
.
Joe Fawcett - 30 Sep 2003 09:59 GMT
> Hello:
>
[quoted text clipped - 15 lines]
> - Paul
> .
Well the easiest way would be to give it an id at creation time <lable
id="lblSurname" for="myformfield"> and then change its innerHTML/innerText
var oLabel = document.getElementById("lblSurname");
oLabel.innerText = "New Value";
//OR
oLabel.innerHTML = "<i>New Value<i>";
if you wish to use formatting.
If you don't have the id, just the identifier of the form field to which it
applies then you need to find it first:
function getLabelFromFormField(FieldId)
{
 var oLabel = null;
 var sFieldId = FieldId.toLowerCase();
 var colLabels = document.getElementsByTagName("label");
 for (var i = 0; i < colLabels.length; i++)
 {
   if (colLabels[i].htmlFor.toLowerCase() == sFieldId)
   {
      oLabel = colLabels[i];
      break;
   }
 }
 return oLabel;
}

I'm not sure if this needs name or id of the form element or will accept
either.

Joe
Signature


Joe

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.