Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a label..

    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:

    Code:
    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?

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,461
    Thanks
    11
    Thanked 600 Times in 580 Posts
    document.appendChild(crtlbl);

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

    or better yet, another element.

    also document.getElementByID should be document.getElementById
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •