Selection of Items/Search of items
I have problem inputting a words i can’t input or click in the search box or maybe i have error in my code or in my script.
My View:
<select type="text" name="protitle" class="form-control" id="recipient-name123" required>
<option>Select Bus</option>
</select>
My script:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryvalidate/1.19.3/jquery.validate.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('#recipient-name123').select2({
ajax: {
url: '<?php echo base_url("projects/searchbus"); ?>',
type: 'POST',
dataType: 'json',
delay: 250,
data: function(params) {
return {
protitle: params.term
};
},
processResults: function(data) {
return {
results: $.map(data, function(item) {
return {
text: item.cat_name + " - " + item.cat_busnum,
id: item.cat_name + " - " + item.cat_busnum
};
})
};
},
cache: true
},
minimumInputLength: 1
});
});
</script>
This is my Model:
public function search_bus($protitle) {
$this->db->like('cat_name', $protitle);
$this->db->or_like('cat_busnum', $protitle);
$query = $this->db->get('assets_category');
return $query->result();
}
This is my controller:
public function searchbus()
{
$protitle = $this->input->post('protitle');
$data['results'] = $this->project_model->search_bus($protitle);
$this->load->view('backend/All_Projects', $data);
}
I just want to search in the select/dropdown and show the data from my database. Do have any suggestion to remove, edit, or add to my code to work? Thank you!