create textbox dynamically

Posted on 2004-11-16
Last Modified: 2008-03-06
I have created a dynamic tree menu and i have placed a checkbox in each to create a textbox while the checkbox of  a levelitem is checked(the textbox should be placed near the levelitem)?
Question by:lword
    LVL 4

    Accepted Solution

    This could be done with javascript. (give a try)
    LVL 2

    Assisted Solution

    Assuming your tree is build of <li> tags

    // define click handler
    function LiChange (e)
        // identify who sent this event
        if (e && {
            // Mozilla browsers
            myTarget =;
        } else {
            // Internet Explorer
            myTarget = this;
            if (event) {
                e = event;
        // delete existing textareas below myTarget
        myTextareas = myTarget.getElementsByTagName('TEXTAREA');
        for (i = 0; i < myTextareas.length; i++) {
        if (myTarget.checked) {
            // create textarea
            myText = document.createElement('TEXTAREA');
            // set name to name of target and append some text
   = + '_text';

    // attach onchange handler dynamically; so you do not need to set an onchange handler in your HTML code
    myLis = document.getElementsByTagName('LI');
    for (i = 0; i < myLis.length; i++) {
        myLi = myLis.item(i);
        myLi.onchange = LiChange;

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now