As the action force of jquery change inside php while loop

Asked

Viewed 134 times

0

Good afternoon, I’m trying to make the action change of jquery work inside a modal that is inside a while loop in php, where I use a select from the STATES field that popular another select from the CITIES field, when I called the first record of my query it works normal and searches the cities according to the state I selected, this is when I do the record editing 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 just doesn’t perform change action by selecting the States field, does anyone know how to force the jquery change on that action? I hope I explained it well!

inserir a descrição da imagem aqui

  • You can make one .each in the options of #ufs and dai for each val() to perform the function

  • Can you elaborate on that? " while loop in php" I think this is creating ID conflicts in the gift so it doesn’t run the second change, it created the click event just for the first id. you can use a class instead of using a conflict-free id and to get the value of the state use $(this). val()

1 answer

0


As I had commented you can try to catch the value of each option of your select through a .each thus :

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.