How to show data in input field when select data at dropdown in Grocery Crud and Codeigniter

MD. ABDUL Halim picture MD. ABDUL Halim · Jan 11, 2013 · Viewed 8.4k times · Source

In Grocery Crud and Codeigniter , Basically i want to show data from one table(such as a_tbl) when select data or id_no(id_no will get from a_tbl) in dropdown then Name and current posting data will take in input field from table(such as a_tbl) , Then Designation, Dept and Section will take in input field from three different table (such as desg_tbl, dept_tbl, sect_tbl).

enter image description here

How can i solve it , Please any help me

Answer

goFrendiAsgard picture goFrendiAsgard · Jan 14, 2013

You can use AJAX. If you use jquery, you can do something like:

$("#field-ID_No").change(function(){
   $.ajax({
      'url':'your_controller/get_name_of_id/'+$("#field-ID_No").val(),
      'success':function(response){
         $("#field-Name").value(response);
      }
   });
});

Basically, when field-ID_No (the select/combobox) changed, the program will send a request to the server (for example: get_name_of_id/1). Assuming, you have "get_name_of_id" function in the controller that echo-ing a name based on given id, you will get the name as response. (Sorry if it sounds complicated). And then, the value of field-Name should be changed with that echoed name.

For more information about AJAX and JQuery, you can read https://stackoverflow.com/a/5004276/755319