View Full Version : Creating a label..

10-15-2008, 08:15 PM
Hi, I have to create a label and then set its 'for' attribute to a bunch of cells in a table. Here's the code I've written so far:

function crtLabel(lblid, lbltxt, lblfor)
var crtlbl = document.createElement('label');
crtlbl.id = lblid;
crtlbl.htmlFor = lblfor;
crtlbl.innerHTML = lbltxt;
crtlbl.style.left = -1000px; //places the label offscreen

function forLabel(lblid, lblfor)
var lbl = document.getElementByID(lblid);
lbl.htmlFor = lbl.htmlFor + " " + lblfor;

The problem is that when I add these functions to other functions as the table cells are being created it breaks the other functions so that they won't run at all. Do you see anything wrong with this code?

rnd me
10-16-2008, 12:25 AM

should perhaps be document.body.appendChild(crtlbl);

or better yet, another element.

also document.getElementByID should be document.getElementById