Run jQuery to select Requester

Asked

Viewed 47 times

1

I got the following jQuery:

function clienteChange() {
    var id = $('#idCliente').val();
    $.ajax( 
    { 
        url:"/Administrar/clientes.endereco.php?id=" + id, 
        dataType : 'json', 
        success:function(result) { 
            $('[name^="cham_endereco[]"]').val(result.endereco); 
            $('[name^="cham_numero[]"]').val(result.numero); 
            $('[name^="cham_bairro[]"]').val(result.bairro); 
            $('[name^="cham_cidade[]"]').val(result.cidade); 
        } 
    }); 

    var selectSolicitante = jQuery(id).parents('tr').find('select.selectSolicitante');
    selectSolicitante.html('<option value="0">Carregando...</option>');
    $.post("/Administrar/clientes.solicitante.php?idCliente=" + id,
        {solicitante:jQuery(id).val()},
        function(valor){
            selectSolicitante.html(valor);
        }
    );
}

The first block works correctly, it displays the data in the address, number... He wanted when selecting the client, to execute this first block but also to execute the second block, searching for the first ones... I took the test, but it doesn’t work.

Follow PHP as well:

    mysql_query("SET NAMES 'utf8'");
    mysql_query('SET character_set_connection=utf8');
    mysql_query('SET character_set_client=utf8');
    mysql_query('SET character_set_results=utf8');

    echo "<option>teste</option>";

The registration screen is this:

inserir a descrição da imagem aqui

  • 1

    What test did you take?

  • I selected the normal client... And the console did not return any errors either... But it does not also display the field options. I put a form print to better understand.

  • Would have to return the test...

  • When you perform the function clienteChange()?

  • <select class="input-xxlarge" style="width: 409px ! Important;" id="idCliente" name="idCliente" onchange="clientChange()" >

  • But what is this select on your screen?

  • At this time, I run it... type, it displays the customer’s address when it selects, but wanted when selecting the customer, also load the requester

  • This select I gave you, is the "Client"

  • The code $.post("/Administrar/clientes.solicitante.php?idCliente=" + id, is executed? Another question, because it is a method POST and you pass the variable on URL?

  • True, I can take out the GET, but it runs the url yes.

  • You can check using console.log(valor) before selectSolicitante.html(valor);? Have you checked if you are sending the id?

  • <option>test</option> Returned this in the console, but not in the field

Show 8 more comments

1 answer

1


Check if your command var selectSolicitante = jQuery(id).parents('tr').find('select.selectSolicitante'); is really returning the element you seek.

My suggestion is, if possible, to give a id or a class to your element, leaving your code like this:

    $(".selectSolicitante").html('<option value="0">Carregando...</option>');
    $.post("/Administrar/clientes.solicitante.php?idCliente=" + id,
        {solicitante:jQuery(id).val()},
        function(valor){
            $(".selectSolicitante").html(valor);
        }
    );

It is important to leave the html(valor) because that way, when your post return the values you need, it will remove the Carrying of his select

  • 1

    It worked, I’m grateful for your help!

Browser other questions tagged

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