ivanichi 0 Light Poster

hello, i have table, like this

i want to create crud for it, this is the new section displaying and retrieving data, with this condition:
nama_barang show with autocomplete,

autocomplete works, and displays the data once selected but does not automatically create a number of data and they remain not separated.

i want: if selected there is an automatic form creation for content in the form of a textarea according to the number of fields in the content field, separated by commas, like this

this my model,

class Jm_model extends CI_Model{
     function search_jm($barang){
        $this->db->like('nama_barang', $barang , 'both');
        $this->db->order_by('nama_barang', 'ASC');
        return $this->db->get('tbl_penjaminan')->result();


class Jm extends CI_Controller{
    function __construct(){

    function index(){

    function get_autocomplete(){
        if (isset($_GET['term'])) {
            $result = $this->jm_model->search_jm($_GET['term']);

            if (count($result) > 0) {
                foreach ($result as $row)
                    $arr_result[] = [
                        'label'         => $row->nama_barang,
                        'description'   => $row->content, // problem here
                         //['description'   => [$row->content]], 

                    echo json_encode($arr_result); 


<!DOCTYPE html>
    <link rel="stylesheet" href="<?php echo base_url().'assets/css/bootstrap.css'?>">
    <link rel="stylesheet" href="<?php echo base_url().'assets/css/jquery-ui.css'?>">
    <div class="container">
        <div class="row">
                 <div class="form-group">
                    <label>Nama Barang</label>
                    <input type="text" class="form-control" id="barang" placeholder="Barang" style="width:500px;">
                  <!--the problem is here ... the content cannot be separated automatically by making the amount of text match the contents of the array-->
                        <div class="form-group">
                        <textarea name="content" class="form-control" placeholder="Content" style="width:500px;"></textarea>

    <script src="<?php echo base_url().'assets/js/jquery-3.3.1.js'?>" type="text/javascript"></script>
    <script src="<?php echo base_url().'assets/js/bootstrap.js'?>" type="text/javascript"></script>
    <script src="<?php echo base_url().'assets/js/jquery-ui.js'?>" type="text/javascript"></script>
    <script type="text/javascript">
            $( "#barang" ).autocomplete({
               source: "<?php echo site_url('jm/get_autocomplete/?');?>",
                select: function (event, ui) {
                    $('[name="content"]').val(ui.item.description); // how to explode
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.