Cita:
Iniciado por Alexis88 Utiliza el método
blur para detectar la pérdida del enfoque en el elemento y con el método
trigger, disparas el evento
submit en el formulario. Un pequeño ejemplo:
Código HTML:
Ver original<form id = "formulario" action = "ejemplo.php"> Dato:
<input type = "text" name = "buscar" /> <input type = "submit" value = "Buscar" />
Código Javascript
:
Ver original$("#formulario").submit(function(e){
e.preventDefault();
$.ajax({
url: $(this).prop("action"),
data: $(this).serialize(),
success: function(response){
$("#salida").val(response);
}
});
});
$("#salida").blur(function(){
$("#formulario").trigger("submit");
});
En el <textarea> se visualizará la respuesta del servidor, es decir, el resultado del procesamiento del dato enviado desde el formulario mediante el método
ajax.
Saludos
Gracias Alexis, pero si mando el formulario al terminar de escribir en el textarea con
blur para que poner ?:
<input type = "submit" value = "Buscar" />
Con esto bastaría?
Lo he intentado así pero no va:
Código Javascript
:
Ver original<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<title>mi bug</title>
</head>
<script type="text/javascript" >
$("#formulario").submit(function(e){
e.preventDefault();
$.ajax({
url: $(this).prop("action"),
data: $(this).serialize(),
success: function(response){
$("#contenido").val(response);
}
});
});
$("#salida").blur(function(){
$("#formulario").trigger("submit");
});
</script>
<body>
<form id = "formulario" action = "ins1_avisos.php">
<table width="79%">
<tr>
<th scope="col" width="57">Teléfonos</th>
<th scope="col" width="52"><input name="telefonos" id="telefonos" type="text" size="9" maxlength="9"/></th>
<th scope="col" width="46">Nombre</th>
<th scope="col" width="88"><input name="name" id="name" type="text" size="35"/>
</th>
<th scope="col" width="46">Apellidos</th>
<th scope="col" width="403"><input name="apellidos" id="apellidos" type="text" size="20" /></th>
<th scope="col"><textarea id = "salida"></textarea></th>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<div id="contenido"></div>
</body>
</html>