in javascript for loop is executing before the get method executes
in following example val e contains all the selected clients from select
box,i am iterating them one by one in for loop and passing them via
jquery's get method to take values according to client but here for loop
is executing before get method ends and due to that it changes the value
of val(which is next value). How to resolve this problem ?
var e = document.getElementById("client");
for (var i = 0; i < e.options.length; i++) {
if(e.options[i].selected){
var val=e.options[i].value;
alert(val); // here it is coming normally
$('#fund').append('<option
value='+select.options.length+'>---'+val+'----</option>');
$.get("listFundsForClient", {client: val}, function(data) {
alert("2nd:"+val);// here it is taking next value due
to for loop iteration
});
}
}
No comments:
Post a Comment