javascript - dynamic dependent dropdown using ajax codeigniter -
i want make dropdown select value , can fetch data database without submit button. paste code here student , making project shall thankful please help...
my controller is
public function find($id) { $product=$this->user_model->find($id); echo "id ".$product->email; }
model
public function find($id) { $this->db->where('id',$id); return $this->db->get('users')->row(); }
view file:
<script type="text/javascript"> $(document).ready(function() { $('#slt').change(function(){ var country_id = $('#slt').val(); $.ajax({ type: 'get', url: "<?php echo base_url('index.php/main/find/')?>"+country_id, success: function(result) { $('#result').html(result); } }); }); }); </script> <form> <input type="button" value="find" id="btnfind"/> <select name="opt" id="slt"> <option value="1">one</option> <option value="2">two</option> <option value="3">one</option> <option value="4">two</option> </select> <br/> <div id="result"></div> </form>
<script type="text/javascript"> $(document).ready(function(){ $('#slt').change(function(){ var country_id = $('#slt').val(); $.ajax({ type:'get', data:country_id, url:"<?php echo base_url('index.php/main/find/')?>", success:function(result) { $('#result').html(result); } }); }); }); </script>
Comments
Post a Comment