0

I have the following code:

$(":input").bind("keyup change", function(e) {
    var comboVal = $('.emailrequerido1').val()+$('.emailrequerido2').val()+$('.emailrequerido3').val()+$('.emailrequerido4').val()+$('.emailrequerido5').val();
    if(comboVal == 'nullnull' || comboVal == ""){
        $("#enviarForm").attr('disabled', true);
    }else{
        $("#enviarForm").removeAttr('disabled');
    }
});

What I am trying to accomplish is that when you select a memorized value from the input box by double clicking in the box a history of inputs shows (these values are saved by the browser (I believe)) and if you choose one of these and the field has that text you selected the button should enable.

Here is a JSFiddle example: JSFiddle example

In the example I added a value to the first field since these dont memorize as I expalined before to show a demonstration of what I mean.

Victor York
  • 1,621
  • 4
  • 20
  • 55
  • Is this relevant to your question: http://stackoverflow.com/questions/11708092/detecting-browser-autofill ??? – A. Wolff Mar 25 '14 at 15:17
  • You could look at things like [Select2](http://ivaynberg.github.io/select2/) that give you a better control on selecting options. – f p Mar 25 '14 at 15:39
  • Comment: Element IDs must be unique. You have many elements with the same ID. Those should be different for each element. I believe you want the classname to be `email_contactopadrino` and the ID to be like `emailrequerido1`. – 000 Mar 25 '14 at 15:42

1 Answers1

0

I have cleaned up the code a bit: http://jsfiddle.net/kam5B/1/

I've swapped the classes and ids so that the ids are unique, and the classes are common.

Here is a checkEmails function that runs the validation and enables/disables the checkbox. checkEmails is run every time an input changes, and when the page loads the first time:

$(document).ready(function () {
    function checkEmails() {
        var nonempty = $('form .email_contactopadrino').filter(function() {
            return $(this).val() != '';
        });
        if (nonempty.length) {
            $('#enviarForm').removeAttr('disabled');
        }
        else {
            $('#enviarForm').attr('disabled', true);
        }
    };
    $('form').on('keyup change', '.email_contactopadrino', checkEmails);
    checkEmails();
});
000
  • 26,951
  • 10
  • 71
  • 101