I have search filter option like checkbox, radibutton how to get the values of checkbox checked value and get the selected radio button and send the value to mysql search query to get the result. Please check with the below code
Note: Right now I am sending the values checkbox and radio button value seperately which will given not exact results as user filtered.
<li><label class="add"><input type="checkbox" class="location_check" name="iCheck[]" value="East Valley">East Valley</label>
</li>
<li><label class="add"><input type="checkbox" class="location_check" name="iCheck[]" value="Central/South Valley">Central/South Valley</label>
</li>
\\radio button
<li><label class="add"><input type="radio" class="budget_filter" name="iCheck" value="open">
OPEN</label></li>
<li><label class="add"><input type="radio" class="budget_filter" name="iCheck" value="500">
LESS THAN $500</label></li>
<li><label class="add"><input type="radio" class="budget_filter" name="iCheck" value="1000">
LESS THAN $1000</label></li>
$('.location_check').on('ifChecked', function(event){
var values = new Array();
$("input.location_check[type=checkbox]:checked").each(function(){;
values.push($(this).val());
})
var track_click = 0; //track user click on "load more" button, righ now it is 0 click
var total_pages = 4;
$.ajax({
url:"<?php echo base_url('search_jobs/fetch_jobs')?>",
type: "POST",
data:'location_checkboxes='+ values +'&page='+track_click,
beforeSend: function(){
$('#loader-icon').show();
},
complete: function(){
$('#loader-icon').hide();
},
success: function (html) {
$('#jobsfound').html(html);
}
})
})
$('.budget_filter').on('ifClicked', function(event){
var get_value= $(this).val();
var track_click = 0; //track user click on "load more" button, righ now it is 0 click
var total_pages = 4;
$.ajax({
url:"<?php echo base_url('search_jobs/fetch_jobs')?>",
type: "POST",
data:'search_data=' + get_value + '&page='+track_click,
beforeSend: function(){
$('#loader-icon').show();
},
complete: function(){
$('#loader-icon').hide();
},
success: function (html) {
$('#jobsfound').html(html);
}
})
})
In Model file
if($this->input->post('search_data')=="open"){
$where = "and rs.budget >= 0";
}else if($this->input->post('search_data')){
$where = "and rs.budget < $this->input->post('search_data')";
}else{
$where = "";
}
echo $where;
if($this->input->post('location_checkboxes')){
$where = "and FIND_IN_SET(a.neighborhood_area, '".$this->input->post('location_checkboxes')."')";
}