Foros del Web » Programando para Internet » Javascript »

TextArea Formato

Estas en el tema de TextArea Formato en el foro de Javascript en Foros del Web. Hola, tengo el siguiente problema: Tengo un TextArea, el cual llevara una descripción mas o menos larga en cuestion a el numero de caracteres. Lo ...
  #1 (permalink)  
Antiguo 30/09/2008, 17:22
 
Fecha de Ingreso: junio-2008
Mensajes: 63
Antigüedad: 16 años
Puntos: 0
TextArea Formato

Hola, tengo el siguiente problema:

Tengo un TextArea, el cual llevara una descripción mas o menos larga en cuestion a el numero de caracteres. Lo que necesito es darle formato al contenido.

Que cuando inicie la captura, automaticamente la primer letra sea mayuscula, despues de un punto sea mayuscula y con espacio.

Alguien tiene un script que pueda facilitarme?

Gracias de antemano
  #2 (permalink)  
Antiguo 01/10/2008, 10:52
 
Fecha de Ingreso: junio-2008
Mensajes: 63
Antigüedad: 16 años
Puntos: 0
Respuesta: TextArea Formato

YA PUDE!!

Ya pude construir un script, para que te convierta en mayusculas la primer letra y la que esta despues de un punto, con su respectivo espacio.

Aqui dejo el script:


function formatogram(nombre)
{

//var mombre = document.getElementById('platica_alta').value;
//alert(nombre);
cad='.';
cad2='*';
//alert(cad);
//alert(cad2);
pos=nombre.indexOf(cad);
//alert(pos);
uno=nombre.substr(0,1); //alert(uno);
longitud = nombre.length;
//alert(longitud);
dos=nombre.substr(1, nombre.length); //alert(dos);
uno = uno.toUpperCase(); //alert(uno);
//$arreglo=explode('.',nombre);


var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = nombre.toLowerCase();
alert(tmpStr);
strLen = tmpStr.length;
alert(strLen);
if (strLen > 0)
{
for (index = 0; index <= strLen; index++)
{
if (index == 0)
{

alert(index);
tmpChar = tmpStr.substring(0,1).toUpperCase();
alert(tmpChar);
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
alert(tmpStr);
}
else
{
alert(index);
tmpChar = tmpStr.substring(index, index+1);
alert(tmpChar);
alert(index);
alert(strLen);
if (tmpChar == "." && index < (strLen-1))
{
alert("IF PUNTO");
tmpChar = tmpStr.substring(index+1, index+2);
alert(tmpChar);
if (tmpChar != " " && index < (strLen))
{
var salto = event.keyCode;
alert(salto);
if (tmpChar == salto && index < (strLen))
{
alert("SALTO");
tmpChar = tmpStr.substring(index+1, index+3).toUpperCase();
alert(tmpChar);
preString = tmpStr.substring(0, index+1);
alert(preString);
postString = tmpStr.substring(index+2,strLen);
alert(postString);
tmpStr = preString + ' ' +tmpChar + postString;
alert(tmpStr);
strLen = strLen+1;
}
else
{
alert("SIN ESPACIO");
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
alert(tmpChar);
preString = tmpStr.substring(0, index+1);
alert(preString);
postString = tmpStr.substring(index+2,strLen);
alert(postString);
tmpStr = preString + ' ' +tmpChar + postString;
alert(tmpStr);
strLen = strLen+1;
}
}
else
{
alert("CON ESPACIO");
alert(index);
tmpChar = tmpStr.substring(index+2, index+3).toUpperCase();
alert(tmpChar);
preString = tmpStr.substring(0, index+1);
alert(preString);
postString = tmpStr.substring(index+3,strLen);
alert(postString);
tmpStr = preString + ' ' +tmpChar + postString;
alert(tmpStr);
strLen = strLen+1;
}
}
}
}
}

document.getElementById('platica_alta').value = tmpStr;
}



AHORA TENGO EL SIGUIENTE PROBLEMA:

Alguien sabe como detectar un salto de linea, para que automaticamente me ponga la primer letra en Mayuscula...

Es lo unico que me falta, detectar un salto de linea...
  #3 (permalink)  
Antiguo 01/10/2008, 11:55
Avatar de TresPuntoDos  
Fecha de Ingreso: septiembre-2008
Ubicación: Madrid, España
Mensajes: 242
Antigüedad: 15 años, 8 meses
Puntos: 3
Respuesta: TextArea Formato

No puedes hacerlo con un evento onkeyup?
  #4 (permalink)  
Antiguo 01/10/2008, 12:12
 
Fecha de Ingreso: junio-2008
Mensajes: 63
Antigüedad: 16 años
Puntos: 0
Respuesta: TextArea Formato

LISTO!!!!


Este es el codigo que utilizo, en un TEXTAREA, al ingresar los datos, con el evento onchange mando llamar esta funcion, enviandole el contenido del textarea que se acaba de capturar.


y el problema del enter(nueva linea) se resolvio con esta funcion:
charCodeAt(index);


Espero que pueda funcionarle a alguien.

PD. Muy pocos aportes ponen eeeeeh, puras dudas y nadie responde

Saludos desde Durango, méxico



function formatogram(nombre)
{

cad='.';
cad2='*';

pos=nombre.indexOf(cad);
uno=nombre.substr(0,1);
longitud = nombre.length;
dos=nombre.substr(1, nombre.length);
uno = uno.toUpperCase();

var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
var
tmpStr = nombre.toLowerCase();

strLen = tmpStr.length;

if (strLen > 0)
{
for (index = 0; index <= strLen; index++)
{

if (index == 0)
{


tmpChar = tmpStr.substring(0,1).toUpperCase();

postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;

}
else
{

tmpChar = tmpStr.substring(index, index+1);

var cara = tmpStr.charCodeAt(index);

if (cara == 13 && index < (strLen-1))
{

tmpChar = tmpStr.substring(index+1, index+3).toUpperCase();

preString = tmpStr.substring(0, index+1);

postString = tmpStr.substring(index+3,strLen);

tmpStr = preString + ' ' +tmpChar + postString;

strLen = strLen+1;
}
else
{
if (tmpChar == "." && index < (strLen-1))
{
tmpChar = tmpStr.substring(index+1, index+2);
if (tmpChar != " " && index < (strLen))
{

tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();

preString = tmpStr.substring(0, index+1);

postString = tmpStr.substring(index+2,strLen);

tmpStr = preString + ' ' +tmpChar + postString;

strLen = strLen+1;

}
else
{

tmpChar = tmpStr.substring(index+2, index+3).toUpperCase();

preString = tmpStr.substring(0, index+1);

postString = tmpStr.substring(index+3,strLen);

tmpStr = preString + ' ' +tmpChar + postString;

strLen = strLen+1;
}
}
}
}
}
}

document.getElementById('platica_alta').value = tmpStr;
}
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 14:16.