Ver Mensaje Individual
  #3 (permalink)  
Antiguo 26/07/2007, 01:28
Avatar de Panino5001
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
Re: Posicion del cursor dentro de un input

Fijate si esto te sirve:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>ejemplo</title>
<
script>
function 
sel(inicio,fin){
input=document.getElementById('area');
if(
typeof document.selection != 'undefined' && document.selection){
tex=input.value;
input.value='';
input.focus();
var 
str document.selection.createRange();
input.value=tex;
str.move('character'inicio);
str.moveEnd("character"fin-inicio);
str.select();
}
else if(
typeof input.selectionStart != 'undefined'){
input.setSelectionRange(inicio,fin);
input.focus();
}
}
function 
devPos(){
input=document.getElementById('area');
if(
typeof document.selection != 'undefined' && document.selection && typeof input.selectionStart == 'undefined'){

var 
str =document.selection.createRange();
stored_range str.duplicate();
stored_range.moveToElementText(input);
stored_range.setEndPoint'EndToEnd'str );
input.selectionStart stored_range.text.length str.text.length;
input.selectionEnd input.selectionStart str.text.length;
alert(input.selectionStart)
}else if(
typeof input.selectionStart != 'undefined'){
alert(input.selectionStart);
}
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <textarea name="area" rows="1" id="area" onclick="devPos()">esta es una prueba</textarea>
  <input type="button" name="Submit" value="seleccionar" onclick="sel(8,11)" />
</form>
</body>
</html> 
(Si lo convertís a input text el selectionStart no funcionará en explorer.)

Última edición por Panino5001; 26/07/2007 a las 01:35