JavaScript - Seleccionar parte del texto de un INPUT

 
Vista:

Seleccionar parte del texto de un INPUT

Publicado por Nicolás (1 intervención) el 03/10/2007 02:16:12
Buenas... el problema que necesito solucionar es el del titulo.
Necesito, mediante javascript, seleccionar solo una porción del texto que hay en un INPUT de tipo TEXT. Alguien sabe como se puede hacer esto? Muchas Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Seleccionar parte del texto de un INPUT

Publicado por Soraya (1 intervención) el 04/10/2007 01:14:11
Hola Nicolás, acá te envio una función que quizas pueda servirte, es con un textArea

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<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();
}
}
</script>
</head>
 
<body>
<form id="form1" name="form1" method="post" action="">
  <textarea name="area" cols="60" rows="10" id="area">esta es una prueba</textarea>
  <input type="button" name="Submit" value="seleccionar" onclick="sel(8,11)" />
</form>
</body>
</html>

Bueno espero que te sirva, cualquier cosa avisa.

Saludos
Soraya
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar

Seleccionar parte del texto de un INPUT

Publicado por Juan De la Rosa (1 intervención) el 24/03/2017 01:26:50
Muchas gracias, era exactamente lo que necesitaba. Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar