How to add the rich textareas dynamically
<textarea name="subtitulo" id="subtitulo" row="12" cols="30" style="width:50%; height:150px"/><?php echo $resultado['subtitulo']; ?></textarea>
<script type="text/javascript">
//<![CDATA[
// This call can be placed at any point after the
// <textarea>, or inside a <head><script> in a
// window.onload event handler.
// Replace the <textarea id="editor"> with an CKEditor
// instance, using default configurations.
CKEDITOR.replace('subtitulo',
{
toolbar : 'Basic',
uiColor : '#9AB8F3'
});
//]]>
</script>
<script language="javascript" type="text/javascript">
//Esta es una variable de control para mantener nombres
var numero = 0;
//diferentes de cada campo creado dinamicamente.
evento = function (evt) { //esta funcion nos devuelve el tipo de evento disparado
return (!evt) ? event : evt;
}
addParrafo = function () {
contRespuestas++;
nDiv = document.createElement('div');
nDiv.className = 'caja';
nDiv.id = 'box' + (++numero);
var ie=(document.all)? true:false;
if (ie) {
nCampoB = document.createElement('nCampoB');
nCampoB.name = nDiv.id;
nCampoB.href = '#';
nCampoB.innerHTML = "<textarea name='parrafos[]' id='parrafos[]' cols='30' rows='12' type='text' />";
nCampoA = document.createElement('nCampoA');
nCampoA.name = nDiv.id;
nCampoA.href = '#';
nCampoA.innerHTML = "<input name='hueco[]' id='hueco[]' type='text' />";
nCampoC = document.createElement('nCampoC');
nCampoC.name = nDiv.id;
nCampoC.href = '#';
nCampoC.innerHTML = "<input name='hueco[]' id='hueco[]' type='text' />";
nCampoD = document.createElement('nCampoD');
nCampoD.name = nDiv.id;
nCampoD.href = '#';
nCampoD.innerHTML = "<input name='hueco[]' id='hueco[]' type='text' />";
} else {
nCampoB = document.createElement('textarea');
nCampoB.name = 'parrafos[]';
nCampoB.id = 'parrafos[]';
nCampoB.cols = '30';
nCampoB.rows = '12';
nCampoA = document.createElement('input');
nCampoA.name = 'hueco[]';
nCampoA.id = 'hueco[]';
nCampoA.type = 'text_area';
nCampoC = document.createElement('input');
nCampoC.name = 'hueco[]';
nCampoC.id = 'hueco[]';
nCampoC.type = 'text_area';
nCampoD = document.createElement('input');
nCampoD.name = 'hueco[]';
nCampoD.id = 'hueco[]';
nCampoD.type = 'text_area';
}
b = document.createElement('b');
b.name = nDiv.id;
b.href = '#';
b.onclick = elimParrafo;
b.innerHTML = 'Eliminar';
nDiv.appendChild(nCampoB);
nDiv.appendChild(nCampoA);
nDiv.appendChild(nCampoC);
nDiv.appendChild(nCampoD);
nDiv.appendChild(b);
container = document.getElementById('respuestasAdmin');
container.appendChild(nDiv);
}
elimParrafo = function (evt){
evt = evento(evt);
nCampo = rObj(evt);
div = document.getElementById(nCampo.name);
div.parentNode.removeChild(div);
var form = document.adminForm;
contRespuestas--;
}
</script>
<a href="#" onClick="addParrafo()">Agregar texto</a>