...

View Full Version : Creating a label..



gbaldeck
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.appendChild(document.createTextNode(lbltxt));
crtlbl.style.left = -1000px; //places the label offscreen
document.appendChild(crtlbl);
}


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
document.appendChild(crtlbl);

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

or better yet, another element.

also document.getElementByID should be document.getElementById



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum