Change values of a div

0

I have a combo when event occurs onchange it performs a query on the database with the selected value and inserts into a div values, the problem is that when I apply $('.minhaDiv').html(resultado) it returns me only the last given, I tried with append and it repeats several data below those consulted previously, what I would need would be that it overlap with all the data the values previously set on the screen.

How could I do this? Any solution?

An example of my code:

$("#dados_solicitacao").on('change','#caminho', function change(){
   var selected = $(this).val();
   var url = urlprojeto+"/minhaUrl.php";
            var data = 'referencia='+selected+'';
            var data = get_contents(url, data);
            var aDados  = data.dados;
            var cDados  = aDados.length;
            for( s=0; s<cDados; s++ )
                {

                    var status      = aDados[s].cad_ativo;
                    var referencia  = aDados[s].cad_referencia;
                    var txt= 'ativo:'+status;
                    txt+= ' minha referencia:'+referencia;
                    $(".div_selected").html(txt);
                }
});

WhatIhaveonthescreen,andIwouldlikeittoalwaysbechangedbychangingthevalueselectedinthecombo.

Becausetheyaredifferentdata,theyneedtobereplaced,becausemycomboservesasafilter,whereinthiscomboInavigatethroughmy"folders" (topics of my site).

    
asked by anonymous 14.12.2015 / 17:25

1 answer

1

Try this,

$("#dados_solicitacao").on('change','#caminho', function change(){
   var selected = $(this).val();
   var url = urlprojeto+"/minhaUrl.php";
            var data = 'referencia='+selected+'';
            var data = get_contents(url, data);
            var aDados  = data.dados;
            var cDados  = aDados.length;
            var txt = '';
            for( s=0; s<cDados; s++ )
                {

                    var status      = aDados[s].cad_ativo;
                    var referencia  = aDados[s].cad_referencia;
                    txt+= 'ativo:'+status;
                    txt+= ' minha referencia:'+referencia;

                }
              $(".div_selected").html(txt);
});

See that you were declaring the variable txt within the for, now the value of txt will suffer an append.

See if that solves your problem.

    
14.12.2015 / 18:42