0

I want to fetch the corresponding value of my dropdown the image below shows the form and the database. the table was inside the Javascript and I am having a difficult time in figuring out this problem.

Database

forms entry

My Controller

function getFeetypeEndDate() { $feetype_id = $this->input->get('feety_id[]'); $data = $this->feegroup_model->getFeetypeByEndDate($feetype_id); echo json_encode($data); } 

My Model

public function get($id = null) { $this->db->select()->from('feetype'); $this->db->where('is_system', 0); if ($id != null) { $this->db->where('id', $id); } else { $this->db->order_by('id'); } $query = $this->db->get(); if ($id != null) { return $query->row_array(); } else { return $query->result_array(); } } 

My Javascript in the View Section

<script> $(document).ready(function (){ $("body").on('click', '.btn-add-more', function (e) { e.preventDefault(); var amount = $("#amount").val(); var penalty = $("#penalty").val(); var $sr = ($(".jdr1").length + 1); var rowid = Math.random(); var $html = '<tr class="jdr1" id="' + rowid + '">' + '<td><span class="btn btn-sm btn-default">' + $sr + '</span><input type="hidden" name="count[]" value="'+Math.floor((Math.random() * 10000) + 1)+'"></td>' + '<td><select id="feetype_id[]" name="feetype_id[]" class="form-control" >' + '<?php foreach ($feetypeList as $feetype) { ?>' + ' <option value="<?php echo $feetype['id'] ?>" ' + '<?php if (set_value('feetype_id[]') == $feetype['id']) { echo "selected =selected"; } ?>><?php echo $feetype['type'] ?></option> <?php $count++; } ?> </select></td>' + '<td><input type="text" id="startDate" name="startDate" value="<?php echo date($this->customlib->getSchoolDateFormat($feetype->start_date), $this->customlib->dateyyyymmddTodateformat($feetype->start_date)); ?>" placeholder="Start Date" class="form-control input-sm"/></td>' + '<td><input type="text" id="endDate" name="endDate" value="<?php echo date($this->customlib->getSchoolDateFormat($feetype->end_date), $this->customlib->dateyyyymmddTodateformat($feetype->end_date)); ?>" placeholder="End Date" class="form-control input-sm"/></td>' + '<td><input type="text" name="amount_td[]" placeholder="Amount" class="form-control input-sm" value="'+amount+'"></td>' + '<td><input type="text" name="penalty_td" placeholder="Penalty" class="form-control input-sm" value="'+penalty+'"></td>' + '</tr>'; $("#table-details").append($html); }); $("body").on('click', '.btn-remove-detail-row', function (e) { e.preventDefault(); if($("#table-details tr:last-child").attr('id') != 'row1'){ $("#table-details tr:last-child").remove(); } }); }); </script> 
5
  • @RP can you show us your an error? please check your console, are you using ajax on add More button? Commented Feb 23, 2019 at 3:51
  • the error is that the starting date and end date dont fetch as in the image below it is always show the default date of 01/01/1970 the date is in the same table as the month Commented Feb 23, 2019 at 3:54
  • But your question is related to drop down list [Month] Commented Feb 23, 2019 at 3:57
  • yes it is related please view the 2 attached images I want to automatically fetch the starting date and the end date in the inputbox when you select the month(feetype) that is my problem Commented Feb 23, 2019 at 3:59
  • Well, from the start I'd say feety_id[] is a typo - that's not what your field is called. Commented Nov 4 at 8:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.