Welcome Guest, Not a member yet? Register   Sign In
DropDown with onchange event
#5

im already wrote some code for dropdown with onchange event but the problem is when i refresh it, it doesnt show the data but after i select different value in dropd down its show the data

View
Code:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript">        
        $(document).ready(function () {
            $('#divTahunAjar select').change(function () {
                var selState = this.value; //value from dropdown tahun ajar
                console.log(selState);
                $.ajax({  
                    url: "<?php echo base_url(); ?>controllers/getDataSekolah/", //The url where the server req would we made.
                    async: false,
                    type: "POST", //The type which you want to use: GET/POST
                    data: "state="+selState, //The variables which are going.
                    dataType: "html", //Return data type (what we expect).
                    
                    //This is the function which will be called if ajax call is successful.
                    success: function(data)
                    {
                        //data is the html of the page where the request is made.
                        $('#result').html(data);
                    }
                })
            });
        });
    </script>

Code:
                  <div id="divTahunAjar">
            <?php
                    $attributes = 'class="form-control"';
                    echo form_dropdown('tahunAjar', $dropDownTahunAjar, '#', $attributes);
            ?>
           </div>

        <div id="result">
        </div>

Controllers
Code:
function getDataSekolah()
        {
            $tahunAjar_id=$_POST['state'];
            $result=$this->mainModels->getDataSekolah($tahunAjar_id);
            print "<br/>";
            foreach($result as $row)
            {
                echo "<li><a href=".base_url()."controllers/processSekolah/".$row->kd_sekolah.">".$row->nama_sekolah." >> ".$row->kota."</a></li>";
            }
        }

Model
Code:
function getDataSekolah($tahunAjar_id)
        {
            $this->db->select('*');
            $this->db->where('kd_thn_ajar', $tahunAjar_id);
            $this->db->join('kepsek','kepsek.kd_kepsek=sekolah.kd_kepsek','left');
            $this->db->join('kota','kota.kd_kota=sekolah.kd_kota','left');
            
            $query = $this->db->get('sekolah');
            return $query->result();
        }
Reply


Messages In This Thread
DropDown with onchange event - by nxs_02 - 03-26-2017, 08:47 PM
RE: DropDown with onchange event - by qury - 03-27-2017, 04:47 AM
RE: DropDown with onchange event - by nxs_02 - 03-28-2017, 05:42 PM
RE: DropDown with onchange event - by nxs_02 - 03-28-2017, 06:00 PM
RE: DropDown with onchange event - by nxs_02 - 03-28-2017, 07:12 PM
RE: DropDown with onchange event - by Martin7483 - 03-29-2017, 05:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB