Thursday, May 6, 2010

JQuery, controlar multiples eventos para remover errores en un formulario HTML

Donde #start_date, #end_date, #rec_until son input=text y el codigo html que remueve el remove() es por ejemplo:

<dd><span class="error error_start_date">Invalid start date (format: mm/dd/yyyy)</span></dd>

Ahora, el codigo en si es el siguiente:

$('#start_date, #end_date, #rec_until').bind('click blur select', function() {
$('.error_' + $(this).attr('id')).fadeOut('slow', function () {
$(this).parent().remove();
});
});

Se que no es muy explicativo, pero lo interesante de esto es la funcion bind() que nos permite manejar diferentes eventos con una misma funcion. Lo que hace el codigo es remover con una animacion fadeOut() el dd+span que se agrego al formulario a causa de un error.

Saludos !

No comments:

Followers

About me

Santa Fe, Argentina
Programador Web, PHP, MySQL, JQuery, Administrador Linux. LAMP, Lighttpd, Nginx.