我有一个月和年的下拉列表,但在提交此下拉列表后,它总是返回默认值(一月(。我使用了Codeigniter
<label>Bulan</label><br>
<select name="bulan">
<!-- <option value="">Pilih</option> -->
<option value="01">Januari</option>
<option value="02">Februari</option>
<option value="03">Maret</option>
<option value="04">April</option>
<option value="05">Mei</option>
<option value="06">Juni</option>
<option value="07">Juli</option>
<option value="08">Agustus</option>
<option value="09">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">Desember</option>
</select>
<script type="text/javascript">
document.getElementById('bulan').value = "<?php echo $_GET['bulan'];?>";
</script>
</div>
<div class="tahun" align="center">
<?php
$now=date('Y');
echo "<select name=tahun>";
for ($a=2010;$a<=$now;$a++)
{
echo "<option value='$a'>$a</option>";
}
echo "</select>";
?>
<script type="text/javascript">
document.getElementById('tahun').value = "<?php echo $_GET['tahun'];?>";
</script>
<br><br>
<input type="submit" name="submit">
</div>
</form>
我从这个问题中引用了这个代码但没用,有人能帮我吗?它是我的控制器
public function view_status(){
$year = $this->input->post('tahun');
$month = $this->input->post('bulan');
$this->data['hasil']=$this->app_model->status_data($year,$month);
$this->load->view('view_status',$this->data);
}
编辑view_status
控制器:
public function view_status(){
$year = $this->input->post('tahun');
$month = $this->input->post('bulan');
$this->data['hasil'] = $this->app_model->status_data($year,$month);
$this->data['bulan'] = $month;
$this->data['tahun'] = $year;
$this->load->view('view_status',$this->data);
}
编辑选择bulan
脚本:
<script type="text/javascript">
document.getElementById('bulan').value = "<?php echo $bulan;?>";
</script>
编辑选择tahun
脚本:
<script type="text/javascript">
document.getElementById('tahun').value = "<?php echo $tahun;?>";
</script>
您的JS是getElementById
,但在下拉列表中没有id,请更新您的下拉列表,如下
<select name="bulan" id="bulan">
...
...
</select>