I have this JQuery code:
jQuery("#form").click(function() {
$("input[name='copyno']:checked").each(function() {
checkboxData = "copyno="+$(this).val();
id=$(this).val();
jQuery.ajax({
url: "renewall.php",
type: "POST",
data: checkboxData,
cache: false,
dataType: "text",
success: function(data) {
$("#" +id).html(data);
}
});
});
});
What I’am trying to do is to put the response data into specific divs based on checkboxes values, in this case the id, but the response data only shows in the same div id (
id=$(this).val();) instead of to be shown there where it has the same id value.
Som Kind og iteration problem
Copy of your code you showed me in the screencast:
Anyway the important part is to properly declare your
idvariable within yourclickfunction like:So do note that var instantiator right before the divs. This should fix your problem. If you don’t do this, the variable is set for the first call, but is overwritten by the second. So eventually when both calls finish, they will just have the same ids value which is your second div.