我有一个这样的控制器:Author
unitselector.php
视图:unitselector
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Unitselector extends CI_Controller {
function __construct() {
parent::__construct();
//$this->load->model(array('Transaksi_model', 'Pelanggan_model'));
//chek_session();
}
function index() {
if (!$this->ion_auth->logged_in()) {
// redirect them to the login page
redirect('auth/login', 'refresh');
} else{
$this->db->order_by("unit_order");
$data['record']= $this->db->get('tb_unit_list')->result();
$unitid = $this->input->get('hiddenInput');
$data['record1']= $this->db->query("SELECT * FROM tb_unit_location where id_unit='$unitid' ")->result();
$data['record2']= $this->db->query("SELECT * FROM tb_period WHERE Status = 0")->result();
$this->load->view('unitselector/unitselector',$data);
}
}
}
问题是:
当用户选择dropdown1时,它会将值返回 <div class="form-group">
<label for="">Unit Name</label>
<select id='dropdown1' name='dropdown1' class="form-control" onclick="changeHiddenInput(this)">
<option value="">Pilih...</option>
<?php
if (!empty($record)) {
foreach ($record as $r) {
echo "<option value=".$r->id_unit.">".$r->unit_name."</option>";
}
}
?>
</select>
<input name="hiddenInput" id="hiddenInput" value="" />
</div>
<div class="form-group">
<label for="">Lokasi/Cabang</label>
<select id='dropdown2' name='dropdown2' class="form-control" onclick="changeHiddenInput1(this)">
<option value="">Pilih...</option>
<?php
if (!empty($record1)) {
foreach ($record1 as $r1) {
echo "<option value=".$r1->id_unit_loc.">".$r1->unit_loc_name."</option>";
}
}
?>
</select>
<input name="hiddenInput1" id="hiddenInput1" value="" />
</div>
<div class="form-group">
<label for="">Periode</label>
<select id='dropdown3' name='dropdown3' class="form-control">
<option value="">Pilih...</option>
<?php
if (!empty($record2)) {
foreach ($record2 as $r2) {
echo "<option value=".$r2->id_period.">".$r2->id_period."</option>";
}
}
?>
</select>
</div>
<div class="row">
<div class="col-xs-4" style="float: right;">
<button type="submit" class="btn btn-primary btn-block btn-flat"><?php echo lang('login_proceed');?></button>
</div><!-- /.col -->
</div>
<?php echo form_close();?> <!--Excutor when button submit goes to controller Dashboard.php -->
。我需要hiddeninput
成为
hiddeninput1
我已经将$data['record1']= $this->db->query("SELECT * FROM tb_unit_location where id_unit='$unitid' ")->result();
定义为值。但它没有效果。请帮忙。
答案 0 :(得分:0)
你可以这样做:
$('#dropdown1').change(function(){
window.location.href = 'unitselector/index?hiddenInput1=' + $(this).val();
});
或者使用ajax加载。