/
seleccionar-campo-formulario.html
38 lines (32 loc) · 1.32 KB
/
seleccionar-campo-formulario.html
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
34
35
36
37
38
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Seleccionar contenido de un campo del formulario</title>
<script type="text/javascript" src="http://lineadecodigo.com/js/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// Con este código seleccionamos el contenido del campo con el id 'texto'
$("#texto").select();
// Con este código seleccionamos el contenido de textarea bajo petición
$("#selectall").click( function(){
$("#areatexto").select();
return false;
});
});
</script>
</head>
<body>
<h1>Seleccionar contenido de un campo del formulario</h1>
<form id="miform">
<label for="texto">Inserta texto:</label>
<input id="texto" type="text" value="Texto por defecto" size="100"/><br/>
<textarea id="areatexto">Texto por defecto</textarea><br/>
<button id="selectall">Seleccionar todo el texto</button>
</form>
<br/><br/>
<hr>
Artículo disponible en: <a href="http://lineadecodigo.com/jquery/seleccionar-el-texto-de-un-campo/">http://lineadecodigo.com/jquery/seleccionar-el-texto-de-un-campo/</a><br/>
<a href="http://lineadecodigo.com" title="Linea de Codigo">lineadecodigo.com</a>
</body>
</html>