segunda-feira, junho 14, 2010

Auto Tab no jQuery

Um script esperto para passar de um campo para outro automaticamente, campos com tamanhos pré definidos.

Virifica mascara tb ;-)

jQuery(":input[maxlength]").keyup(function () {
    var focus = jQuery(this);
    var valFocus;
    try {
        if (typeof jQuery(focus).mask() == 'string') {
            valFocus = jQuery(focus).val().replace("_", "");
        }          
    } catch (e) {
        valFocus = jQuery(focus).val();      
    }

    if (focus.attr('maxLength') == valFocus.length) {
        var next = false;
        jQuery(":input[maxlength]").each(function(element) {  
            if (next) {
                jQuery(this).focus();
            }
            next = false;
            if (jQuery(this).attr('id') == focus.attr('id')) {
                next = true;
            }
        });
    }
})

enjoy!