Welcome Guest, Not a member yet? Register   Sign In
value autocomplete
#1

[eluser]Unknown[/eluser]
controller:
Code:
function lookup(){
        // process posted form data (the requested items like province)
        $keyword = $this->input->post('term');
        $data['response'] = 'false'; //Set default response
        $query = $this->MAutocomplete->lookup($keyword); //Search DB
        if( ! empty($query) )
        {
            $data['response'] = 'true'; //Set response
            $data['message'] = array(); //Create array
            foreach( $query as $row )
            {
                $data['message'][] = array(
                                        'id'=>$row->propinsi_id,
                                        'value' => $row->propinsi,
                                        ''
                    );  //Add a row to array
            }
        }
        if('IS_AJAX')
        {
            echo json_encode($data); //echo json string if ajax request

        }
        else
        {
            $this->load->view('autocomplete/index',$data); //Load html view of search results
        }
    }
model:
Code:
function lookup($keyword){
        $this->db->select('*')->from('propinsi');
        $this->db->like('propinsi',$keyword,'after');
        $query = $this->db->get();  

        return $query->result();
    }
view:
Code:
[removed]
        $(this).ready( function() {
            $("#provinsi_id").autocomplete({
                minLength: 1,
                source:
                function(req, add){
                    $.ajax({
                        url: "<?php echo base_url(); ?>index.php/autocomplete/lookup",
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                        function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
            select:
                function(event, ui) {
                    $("#result").append(
                        "<li>"+ ui.item.value + "</li>"
                    );
                },
            });
        });
        [removed]
&lt;body&gt;
        Nama Provinsi :
        &lt;?php
            echo form_input('provinsi','','id="provinsi_id"');
        ?&gt;
        <ul>
            <div id="result"></div>
        </ul>
    &lt;/body&gt;
value above contains $ row-> province so that if the form input typed letters will appear the provinces .. I want to send the form to a database value [$ this-> input-> post ('province)] right value value that will be automatically saved to db is "jambi" or $ row-> province. I was asking how to value that will be sent to the database is $ row-> propinsi_id?

thanks




Theme © iAndrew 2016 - Forum software by © MyBB