Results 1 to 3 of 3

Thread: can you help me to write code for "remove textarea"

  1. #1
    Join Date
    Nov 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question can you help me to write code for "remove textarea"

    can you help me to write code for "remove textarea" button?
    <html>
    <head>
    <script language="javascript">
    function genBox(n)
    {
    var thebox = document.createElement('textarea');
    thebox.setAttribute('rows','10');
    thebox.setAttribute('cols','30');
    thebox.setAttribute('id','textBoxId');
    document.getElementById(n).appendChild(thebox);
    var but=document.createElement('input');
    but.setAttribute('type','button');
    but.setAttribute('value','remove textarea');
    but.setAttribute('name','remove');
    document.getElementById('boxhold1').appendChild(but);

    }
    </script>
    </head>
    <body>
    <input name="Input" type=button onclick="genBox('boxhold1')" value="insert textarea" />
    <div id="boxhold1"></div>
    </body>
    </html>

  2. #2
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    HTML Code:
    <html>
    <head>
    <script language="javascript">
    function genBox(n)
    {
    var thebox = document.createElement('textarea');
    thebox.setAttribute('rows','10');
    thebox.setAttribute('cols','30');
    thebox.setAttribute('id','textBoxId');
    document.getElementById(n).appendChild(thebox);
    var but=document.createElement('input');
    but.setAttribute('type','button');
    but.setAttribute('value','remove textarea');
    but.setAttribute('name','remove');
    but.onclick = function() {
        this.previousSibling.removeNode(true);
        this.removeNode(true);
    };
    document.getElementById('boxhold1').appendChild(but);
    }
    </script>
    </head>
    <body>
    <input name="Input" type=button onclick="genBox('boxhold1')" value="insert textarea" />
    <div id="boxhold1"></div>
    </body>
    </html>
    Same ID for all textareas is not good though.

    Btw. it only works if there's nothing between the textarea and the remove button, else IDs should be used.

  3. #3
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    Hi there DimX,

    are you aware that removeNode will not work in Firefox?

    forjavascript, you may see a crossbrowser solution here...

    coothead

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
  •