Foros del Web » Programando para Internet » Javascript »

Botón para agregar etiquetas en un textarea?

Estas en el tema de Botón para agregar etiquetas en un textarea? en el foro de Javascript en Foros del Web. Hola gente. Estuve revisando el FAQ y encontré algo parecido, pero necesito algo mucho más simple. Quiero tener 4 botones arriba de una textarea que ...
  #1 (permalink)  
Antiguo 15/07/2011, 03:23
 
Fecha de Ingreso: marzo-2009
Mensajes: 27
Antigüedad: 15 años, 1 mes
Puntos: 0
Botón para agregar etiquetas en un textarea?

Hola gente.
Estuve revisando el FAQ y encontré algo parecido, pero necesito algo mucho más simple.
Quiero tener 4 botones arriba de una textarea que envuelvan el texto seleccionado con distintas etiquetas cada uno. Como los botones para poner código PHP del foro.
Estuve probando el CKEditor pero es demasiado complejo y me cambia toda la estructura.

En fin, cómo puedo aplicar que apretando un botón le agregue las etiquetas [ b ] y [ /b ] a un texto seleccionado en la textarea?

Gracias!
  #2 (permalink)  
Antiguo 15/07/2011, 05:22
Avatar de ceSharp  
Fecha de Ingreso: octubre-2008
Ubicación: Madrid
Mensajes: 495
Antigüedad: 15 años, 6 meses
Puntos: 66
Respuesta: Botón para agregar etiquetas en un textarea?

buenas,
esto yo creo que ya salió alguna vez, porque en mis archivos de pruebas lo tenía...
--------------------
function instag(tag){
var input = document.getElementById('contenido');
if(typeof document.selection != 'undefined' && document.selection) {
var str = document.selection.createRange().text;
input.focus();
var sel = document.selection.createRange();
sel.text = "[" + tag + "]" + str + "[/" +tag+ "]";
var pos = new Number(3 + tag.length);
sel.move('character',pos - (2 * pos));
sel.select();
return;
}
else if(typeof input.selectionStart != 'undefined'){
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
input.value = input.value.substr(0, start) + '['+tag+']' + insText + '[/'+tag+']'+ input.value.substr(end);
input.focus();
input.setSelectionRange(start+2+tag.length+insText .length+3+tag.length,start+2+tag.length+insText.le ngth+3+tag.length);
return;
}
else{
input.value+=' ['+tag+']Reemplace este texto[/'+tag+']';
return;
}
}
-----------------------------
<input type="button" name="Submit" value="B" onclick="instag('b')"/>
<textarea id="contenido" cols="40" rows="10" ></textarea>
-----------------------------

saludos.
  #3 (permalink)  
Antiguo 15/07/2011, 05:29
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Botón para agregar etiquetas en un textarea?

http://www.forosdelweb.com/1755928-post244.html
  #4 (permalink)  
Antiguo 15/07/2011, 21:35
 
Fecha de Ingreso: marzo-2009
Mensajes: 27
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Botón para agregar etiquetas en un textarea?

Muchas gracias, no había visto ese post.

Acá dejo otro que encontré justo hoy, muy parecido y demasiado fácil de usar.

[URL="http://www.coders.me/web-html-js-css/javascript/crear-un-toolbar-para-formatear-texto-en-un-textarea"]http://www.coders.me/web-html-js-css/javascript/crear-un-toolbar-para-formatear-texto-en-un-textarea[/URL]

Gracias nuevamente. Saludos!

Etiquetas: etiquetas, php, botones
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:38.