0
I have a combo when the event occurs onchange
it performs a query in the database with the selected value and inserts it into a div
values, the problem is that when I apply $('.minhaDiv').html(resultado)
it returns me only the last data, I tried with append
and it repeats several data below the previously consulted ones, what I would need would be that the same superimposed with all data the values previously arranged 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);
}
});
What I have on the screen, and I would like it to be always changed when changing the value selected in the combo.
Because they are different data it is necessary to replace them, because my combo serves as a filter, where in this combo I navigate through my "folders" (topics of my site).
the correct would not be you put
$(".div_selected").html(txt);
outside the block offor
?– Marconi
I’ve done this and keep returning only the last interaction of
for
– Marcos Henrique
If possible post as is your date. What is printing and what should print. It will help a lot.
– Marconi
The way you are doing, the contents of the div will be replaced every time you enter the loop. The function
html
overwrite all html by new. You have to useappend
orprepend
to do this, as for the problem you reported, I think it’s with your data.– Pedro Camara Junior
but how could I do it any other way, because I know that html changes values, and inside it will change every time it goes through the loop
– Marcos Henrique
Marcos, can you explain HTML better and what you want to do? you have a select and how many elements should get what’s in
txt
? You’re re-declaring the variables inside thefor
why: it must have different values and not concatenate?– Sergio