database - How do I get the selected value in the dropdown and then display further information -


i have dropdown fetches options database. know how can value of selected option after selecting, other datas database displayed in table or form? this

before selecting

select dropdown : option1

name:
age:

after selecting

select dropdown : option2

name: michael
age: 21

controller

 public function salesorders() {         if ($this->session->userdata('logged_in')) {             $this->header2();             $data['groups'] = $this->secretary_model->getallgroups();             $this->load->view('secretary/transactions',$data);         } else {             redirect('secretary/sec_login_view');         }     } 

model

function getallgroups()     {          $query = $this->db->query('select firstname tblcustomer');          return $query->result();      } 

view

<?php              echo "select customer";             $options = array();             foreach($groups $group)             {                $options[$group->firstname] = $group->firstname;             }             echo form_dropdown('dropdown', $options);             ?>             <br>             <br>             <br>                     <table id="mytable" class="table table-bordered" >                           <thead >                               <tr>                                    <th>order #</th>                                   <th>customer name </th>                                   <th>items</th>                                   <th>note</th>                                   <th>qtt.</th>                                  <th>total price</th>                                  <th>shipping address</th>                                  <th>status</th>                                   <th>edit</th>                                </tr>                           </thead>                           <tbody>   

seems need populate first dropdown fields on page loading, need ajax call method pass selected name. in method have code pass ajax input value model returns data value (in case name) wich echo json_encode ajax.

$(document).ready(function(){     $('.dropdownelementclass').on('change', function(){         var value = $(this).val();         $.ajax({             method: "post",             url: "<?php echo base_url('secretary/getdatabyname');?>",              data: { name: value }         })         .done(function( output ) {               $('.classofelementexpectingdata').text( output );         });     }); }); 

//next code controller

public function getdatabyname() {     if ($this->input->is_ajax_request()) {         echo $this->secretary_model->getdatabyname( $this->input->post('name') ) != false ? json_encode( $this->name_m->getdatabyname( $this->input->post('name') ) ) : 'no data selected name.' ;     } else {         echo 'no direct script access allowed.';     } } 

there fair amount of tutorials can search on google or on youtube that. study this one, though. or search "codeigniter ajax" on place first. believe can find many similar questions , answers. luck.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -