javascript - Ajax Onchange replace div not working -
i have select box onchange,
<select class="form-control" onchange="getval(this.value,'<?php echo $prd->pr_id;?>','ajax<?php echo $key?>','<?php echo $key ?>')">
and ajax div in foreach loop,
foreach($name $names) { <div id = "ajax<?php echo $key?>" content </div> }
my ajax function:
function getval(id,prid,divid,key) { alert(divid) $.ajax({ type: "post", data: "aid="+id+"&prid="+prid, url: '<?php echo site_url('grocery/onchange')?>', success: function(html){ $('#'+divid).html(html); }; }); }
i tryimg change div content..but not working?
you need lot of changes in ajax-
first use console.log()
instead of alert , because div's id(s)
being created dynamically need handle in way-
$.ajax({ type: "post", data: {aid:id,prid:prid}, url: '<?php echo site_url('grocery/onchange')?>', success: function(html){ $(document).find('div[id='+divid+']').html(html); }; });
here live example- http://jsfiddle.net/x4lvfk9k/
Comments
Post a Comment