I am working on ajax with jquery,Right now I am using jquery "autocomplete" function So after I enter some characters I am getting list of records with checkbox but problem is that "I can't post previous checked checkbox records",Means if I search something and select some check boxes and then do another search and select some checkbox then the previous checked checkbox value is not posting,How can I do this ? I tried with following code but not working correctly (only posting current select/checked records),Where I am wrong ? Thank you in advance
<input type="text" id="autouser" name="coin" class="form-control">
<div id="resultDiv"></div>
<script type='text/javascript'>
$(document).ready(function(){
$( "#autouser" ).autocomplete({
source: function( request, response ) {
// Fetch data
$.ajax({
url:'<?php echo base_url();?>main/CoinReords',
type: 'post',
dataType: "json",
data: {
search: request.term
},
success: function( data ) {
$("#resultDiv").html("");
$.each(data, function(i, record) {
console.log(record.label);
$("#resultDiv").append("<input type='checkbox' value='" + record.label + "' id='chk-" + i + "' name='CoinName[]' /> " + record.label);
});
}
});
},
select: function (event, ui) {
$('#autouser').val(ui.item.label); // display the selected text
$('#resultDiv').selectedItems.push(ui.item.label);
return false;
}
});
});
</script>