elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
26 Mayo 2012, 14:23  


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)

+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  problema al insertar texto en un area de texto
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: problema al insertar texto en un area de texto  (Leído 583 veces)
RedZer


Desconectado Desconectado

Mensajes: 654



Ver Perfil
problema al insertar texto en un area de texto
« en: 20 Julio 2011, 23:29 »

bueno estoy realizando la opcion de poner texto en negritas,alinear ala izquierda,centrar, y justificar asi como las opciones k tiene el foro  todo eso funciona ala perfeccion el problema surge  cuando por ejemplo yo selecciono una palabra la cual deceo poner en negritas y pulso el icono de negritas el codigo me lo inserta el final ejemplo
si yo tengo seleccionado y deceo poner en negritas mi nombre RedZer al pulsar el icono de negritas me lo aroja al final asi
Código
[b] [/b]
cuando lo que deberia de hacer es esto
Código
[b]RedZer[/b]
anexo parte del  code que ocupo
este scrip es para que los codigos se inserten en el area de texto
Código
<script language="javascript"> 
     <!--  
     function Smile(texto)
 {
     document.formulario.msj.value = document.formulario.msj.value + texto;
     }
</script>
 

y este es el k ocupo para elegir las opciones
Código
<a href=javascript:Smile('[b][/b]')><img src=../letras/bold.gif border=0 title="Negritas"></a> 


« Última modificación: 23 Julio 2011, 21:02 por RedZer » En línea

Nacido y criado entre gente que enseño a pensar antes de creer a ciegas, Todo me causa curiosidad en el mundo
4rkn63l

Desconectado Desconectado

Mensajes: 197



Ver Perfil
Re: problema al insertar texto en un area de texto
« Respuesta #1 en: 24 Julio 2011, 06:43 »

Bueno a mi entender con tu codigo javascript estarias modificando todo el texto que se encuentre en el campo "msj" y no solamente el texto seleccionado, lo que necesitas es solo trabajar con esa parte (rango) de texto seleccionado, esto te ayudara http://www.disegnocentell.com.ar/notas2.php?id=206


En línea
RedZer


Desconectado Desconectado

Mensajes: 654



Ver Perfil
Re: problema al insertar texto en un area de texto
« Respuesta #2 en: 26 Julio 2011, 00:41 »

buscnado una solucion al problema encontre un code muy bueno la funcion que tiene es
hacer un editor de bbCode sencillo que admita selección de texto
y aki el code
Código
 
<html>
<head>
<title>Editor bbCode</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function instag(tag){
var input = document.form1.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+ "]";
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.length+3+tag.length);
return;
}
else{
input.value+=' ['+tag+']Reemplace este texto[/'+tag+']';
return;
}
}
function inslink(){
var input = document.form1.contenido;
if(typeof document.selection != 'undefined' && document.selection) {
var str = document.selection.createRange().text;
input.focus();
var my_link = prompt("Enter URL:","http://");
if (my_link != null) {
if(str.length==0){
str=my_link;
}
var sel = document.selection.createRange();
sel.text = "[a href=\"" + my_link + "\"]" + str + "[/a]";
sel.select();
}
return;
}else if(typeof input.selectionStart != 'undefined'){
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
var my_link = prompt("Enter URL:","http://");
if (my_link != null) {
if(insText.length==0){
insText=my_link;
}
input.value = input.value.substr(0, start) +"[a href=\"" + my_link +"\"]" + insText + "[/a]"+ input.value.substr(end);
input.focus();
input.setSelectionRange(start+11+my_link.length+insText.length+4,start+11+my_link.length+insText.length+4);
}
return;
}else{
var my_link = prompt("Ingresar URL:","http://");
var my_text = prompt("Ingresar el texto del link:","");
input.value+=" [a href=\"" + my_link + "\"]" + my_text + "[/a]";
return;
}
}
</script>
</head>
 
<body>
<form name="form1" method="post" action="">
<input type="button" name="Submit" value="B" onClick="instag('b')">
<input type="button" name="Submit3" value="U" onClick="instag('u')">
<input type="button" name="Submit4" value=" I " onClick="instag('i')">
<input type="button" name="Submit2" value="LINK" onClick="inslink()">
<br>
<textarea name="contenido" cols="40" rows="10" id="contenido"></textarea>
 
</form>
</body>
</html>
 
 
En línea

Nacido y criado entre gente que enseño a pensar antes de creer a ciegas, Todo me causa curiosidad en el mundo
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Problema para insertar texto con un BAT
Scripting
drrub 2 2,226 Último mensaje 4 Octubre 2008, 15:57
por drrub
Area de texto a base de datos mysql
Desarrollo Web
grinfelds 6 797 Último mensaje 21 Diciembre 2008, 02:26
por grinfelds
Problema de texto al poner un texto muy largo, alguna forma de cortarlo?
PHP
tomeu00 5 3,261 Último mensaje 21 Junio 2010, 04:51
por tomeu00
Poner Texto en Text Area javascript
Desarrollo Web
Pafate 1 2,517 Último mensaje 21 Febrero 2011, 03:53
por Nakp
Problema extraño al insertar texto.
.NET
Edu 1 424 Último mensaje 24 Abril 2011, 00:29
por Edu
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines