title: How can I insert the reference ID of one table into another table?
body: <p>I want to add the data by use javascript but i think i can get the id from reference table that why i can't add the data. Please Help.</p>
  
  <p>This my view page.</p>
  
  <pre><code>&lt;div  id="tbl_add_new"&gt;
      &lt;input type="hidden" name="id" id="id" value="&lt;?php echo $this-&gt;uri-&gt;segment(3);?&gt;"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td style="width: 50%; text-align: right;"&gt;Date :&lt;/td&gt;
              &lt;td style="width: 50%; text-align: left;"&gt;&lt;input type="text" id="date" name="date" placeholder="Date" value="" class="frm_text_full"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style="width: 50%; text-align: right;"&gt;No.Doc :&lt;/td&gt;
              &lt;td style="width: 50%; text-align: left;"&gt;&lt;input type="text" rows="2" cols="40" id="no_doc" name="no_doc" value="" placeholder="No.Doc" class="frm_text_full"&gt;&lt;/textarea&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;a href="javascript:;" id="add_new_code" class="frm_button" &gt;Save&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This my Controller </p>
  
  <pre><code>function add_lines(){
      $id = $this-&gt;uri-&gt;segment(3);
      $date = $this-&gt;input-&gt;post('date');
      $no_doc = $this-&gt;input-&gt;post('no_doc');
  
      $data = array(
              'id_lines_code' =&gt; $this-&gt;m_stock-&gt;generate_id(),
              'id'  =&gt; $id,
              'date'  =&gt; $date,
              'no_doc' =&gt; $no_doc
      );
      $this-&gt;m_stock-&gt;add_detail($data);
      $data['lines'] = $this-&gt;m_stock-&gt;get_detail($id);
      $this-&gt;load-&gt;view('v_line_stocks',$data);
  }
  </code></pre>
  
  <p>This my model for show the line in reference id</p>
  
  <pre><code>function get_lines($id){
      $result = array();
      $this-&gt;db-&gt;select('*');
      $this-&gt;db-&gt;from('tbl_lines_code');
      $this-&gt;db-&gt;where('id',$id);
      $this-&gt;db-&gt;order_by('date', 'ASC');
      $query = $this-&gt;db-&gt;get();
      if ($query-&gt;result() &gt; 0) {
          $result = $query-&gt;result();
      }
      return $result;
  }
  </code></pre>
  
  <p>Thank you.</p>