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

(03-26-2017, 08:47 PM)nxs_02 Wrote: I want to ask about if i want make dropdown with onchange event, so basically for every diferent option in dropdown value it will show diferent data, anyone can help me with the basic code?

Hi,

I hacked together the below javascript code using x-editable and DataTables, the way it works is the following:

- on page load the user is presented with a data table, for each row, there are 2 columns
- user has to select a value in column1 (drop-down) which will make the field in column 2 an editable drop-down as well.


Code:
   function editable() {
           // turn to inline mode
           $.fn.editable.defaults.mode = 'inline';
           $('.dropdown').editable({
               url: 'http://datamodel.info/index.php/workflow/ajax_mdg_ui_remove/',
               showbuttons: false,
               source: 'http://datamodel.info/index.php/workflow/ajax_mdg_entity_list/',
               params: function (params) {  //params already contain `name`, `value` and `pk`
                   var data = {};
                   data['field_id'] = $(this).data('pk');
                   data['wf_object'] = 'wf_customer';
                            data['value'] = params.value;
                   return data;
               },
               success: function (response, newValue) {
                   $id = $(this).data('pk');
                   $('#wfeditable2_' + $id).editable.defaults.mode = 'inline';
                   $('#wfeditable2_' + $id).editable('option', 'showbuttons', false);
                   $('#wfeditable2_' + $id).editable('option', 'params', function (params) {  //params already contain `name`, `value` and `pk`
                       var data = {};
                       data['field_id'] = $(this).data('pk');
                       data['entity_type'] = newValue;
                       data['wf_object'] = 'wf_customer';
                       data['attribute'] = params.value;
                       data['comment'] = $(this).data('table') + '-' + $(this).data('field');
                       return data;
                   }
                   );
                   $('#wfeditable2_' + $id).editable('option', 'url', 'http://datamodel.info/index.php/workflow/ajax_mdg_entity_update/' + newValue);
                   $('#wfeditable2_' + $id).editable('option', 'source', 'http://datamodel.info/index.php/workflow/ajax_mdg_attirbute_list/' + newValue);
                   $('#wfeditable2_' + $id).editable('setValue', null);
               }

           });
       }
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