0

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);

}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by PsychicTide
0
function takeBack(newestDivNumber)
{
    var one = document.getElementById('parentDiv');
    var two = document.getElementById('newestDivNumber');
    one.removeChild(two);
}

Let me know if it points you in the right direction.

Edited by PsychicTide: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.