Hi guys,
Please, everybody can help me with my linked select. I use Codeigniter and jquery. Now i just try to get the string of data by received value from first form (year). The value is received properly but i have problems with that i can`t post this value to my controller`s function. In the future I will try to integrate this string to the second form but now is necessary to solve the first thing. Where is an error? What i do wrong?
View:
- <div class="form-order">
<?php echo form_label('Journal year') ?></br><p></p>
<?php echo form_dropdown('journal_year',$j_years, set_select('journal_year'), 'id="year"'); ?>
</div>
<div class="form-order">
<?php echo form_label('Journal Volume/Number') ?></br>
<?php echo form_dropdown('journal_volume', set_select('journal_volume'), ' id="volume"'); ?></br>
</div>
<script type="text/javascript">
function populateYears() {
var year = $('#year').val();
$.post("journal/_get_journal_volumes()", {'year' : year},
function(data) {
alert(data.j_volumes);
}, "json");
}
$(document).ready(function() {
populateYears();
$('#year').change(function() {
populateYears();
});
});
</script>
Controller`s function
- public function _get_journal_volumes(){
- $year =$this->input->post('year');
$this->db->where('journal_year', $year);
$this->db->order_by('journal_volume, journal_issue','asc');
$journal_volumes = $this->db->get('journals');
$j_volumes = array();
foreach($journal_volumes->result_array() as $journal_volume){
$j_volumes[$journal_volume['journal_id']] = "Volume ".$journal_volume['journal_volume']." / Issue ".$journal_volume['journal_issue'];
}
echo json_encode($j_volumes);
}