Jump to content

Recommended Posts

This code adds a new textarea when i press the "add" button.  How do i alter the code so it can remove a textarea.

 

e.g. i added 4 textarea's but i only intended to add 3, how do i delete the 4th textarea?

 

<div id='newdiv'>
</div>

 

<input type='button' onclick='new()' name='add' value='Add' style='font-size:12px;' />

 

 
function new() {
var htmlText =  "<div class='container'><textarea name='reason[]' style='font-size: 10px;width:500px; height:50px;' onFocus='if(this.value==\"type more information"\") { this.value=\"\"}'>type more information</textarea></div>"; 
      		
        var newElement = document.createElement('div');

        newElement.id = 'new1'; // Give the DIV an ID, if you need to reference it later...

 newElement.innerHTML = htmlText;

     var fieldsArea = document.getElementById('newdiv');
fieldsArea.appendChild(newElement);

}

Link to comment
https://forums.phpfreaks.com/topic/233226-remove-textarea-with-button/
Share on other sites

Removing a textarea element is not a matter of simply modifying  that code you pasted. You need new functionality to accomplish what you are describing. You could add a new delete button with the textarea you create and add a delete event for the textarea element next to it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.