How to force jquery change action within php while loop

0

Good afternoon, I'm trying to make the jquery change action work within a modal that is within a while loop in php, where I use a select from the STATES field that populated another select from the CITIES field when I ran the first record of my query it works normal and searches the cities according to the state that I selected, this is when I do the registry edit process, follow the script:

    //FUNCAO  PEGAR CIDADES NATURALIDADE
    $(function (){
        $("#ufs").change(function(){//aqui a função é ativa qdo o usuário sair do campo cpf
            var estados = $("#ufs").val();
            $.post("includeAjax/carregar-cidades.php", {id:estados},
                function(pegar){ $("#cidades").html(pegar); });
        });
    });

More when I edit the second record and open the modal, and I will trigger the select, it simply does not perform change action when selecting the States field, does anyone know how to force the jquery change on that action? I hope I have explained it right!

    
asked by anonymous 17.11.2017 / 19:38

1 answer

0

As I mentioned you can try to get the value of each option of your select through a .each like this:

$(function() {
    $("#ufs option").each(function(){
        var value = $(this).val();
        // seu codigo ...
    });
});

You can test there and see if it works for you anything from a touch I see how to improve the answer if that is not enough to help you

    
17.11.2017 / 19:54