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.
Bookmarks