SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Apr 2004
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    add label to a form dynamically

    I'm using this to add a label to a form. I'm adding new form inputs so the user can add links:

    var obj = document.createElement("label");
    obj.setAttribute("for", "link"); //this seems not to work in IE6

    var myText = document.createTextNode("Label name");
    obj.appendChild(myText);
    document.getElementById("Links").appendChild(obj); //there's a void div called "Links" in the html
    obj = document.createElement("input");
    obj.setAttribute("type", "text");
    obj.setAttribute("name", "link");
    obj.setAttribute("id", "link");


    In the html I use a link that calls the function to add dynamically the input and label.

    It's working ok in Firefox... I mean, when you click on the label, the input get the focus (just as a normal html label tag).

    But it does not work in IE6... Does anybody knows if there's some change to make it work in IE6?

    Thanks a lot

  2. #2
    SitePoint Addict
    Join Date
    Apr 2004
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solved! I found that this:

    obj.htmlFor = "link";

    Works in both IE6 and Firefox...

    I was wondering where I could find all these properties in just one site or guide, I'm getting crazy searching in google everytime I need to use one of this properties

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,597
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    All of the attributes are the same in Javascript as in HTML except for those that are Javascript reserved words.

    className - class
    htmlFor - for

    I think that's the complete list.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Addict
    Join Date
    Apr 2004
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Really? Thanks!


Bookmarks

Posting Permissions

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