1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need some advice on dynamically added fields

Discussion in 'JavaScript' started by rajib.bahar, Oct 1, 2009.

  1. #1
    A recent solution of mine in JavaScript involves dynamic creation of additional input of type text. This is to accommodate the scenario when the user has used up all existing text fields. Are there good articles or guidelines on delivering this solution? I plan to do the basic due dilligence... i.e. making sure dyanmic fields have data, within the bound.

    What challenges have you guys seen?
     
    rajib.bahar, Oct 1, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Using a combination of createElement and appendChild you can add any type of new element to the document, there is other ways to do this but I found that this worked best:
    
                var div1 = document.getElementById("myDiv");
                .................
    
                tbox = document.createElement("input");
                tbox.setAttribute("type","text");
                ...(set other attributes here)...
                div1.appendChild(tbox);
    
    Code (markup):
     
    Last edited: Oct 2, 2009
    camjohnson95, Oct 1, 2009 IP