5
I have a system that has 3 selects, where selecting an option in the 1st select is listed a list in the 2nd select and selecting an option in the 2nd select, is listed the items in the 3rd.
The problem occurs between the 2nd and 3rd, when I select an option in the 2nd select it lists the options for the 3rd and I select, when I go to the next row and select another option in the 2nd select it changes the 3rd select that I had previously selected.
I selected the first option of the second select and listed the items
I go to the second line and select another option in the 2nd select and the 3rd select is reset in the previous option.
-> relationship model between 2º and 3º select
function carregatecidoss($grupoT) {
//$this->db->start_cache();
//$this->db->trans_strict(TRUE);
$this->db->select('idtec, nometec, grupotecido, empresatecidoid');
$this->db->from('tecidos');
$this->db->where('grupotecido', $grupoT);
$this->db->order_by ('nometec' , 'ASC' );
//$this->db->limit(1);
$query = $this->db->get();
if ($query) {
return $query->result();
} else {
return false;
}
}
-> controller
function verificatecidosgrupos() {
if ($this->session->userdata('logged_in')) { // valida usuário logado
$session_data = $this->session->userdata('logged_in');
$usuarioid = $session_data['UsuarioId'];
$option = '';
if ($this->input->post('grupoT')) {
$grupoT = $this->input->post('grupoT');
var_dump($grupoT);
$this->load->model('model_geral');
$tecidos = $this->model_geral->carregatecidoss($grupoT);
if ((isset($tecidos)) && (!empty($tecidos))) {
foreach ($tecidos as $grupo) {
$option .= '<option value="' . $grupo->idtec . '">' . $grupo->nometec . '</option>';
}
echo $option;
} else {
$option = '<option>Grupo tecidos não encontrado!</option>';
echo $option;
}
} else {
$option = '<option>Grupo tecidos não encontrado! Contate o administrador!</option>';
echo $option;
}
} else {
$option = '<option>SESSÃO EXPIRADA</option>';
echo $option;
}
}
->jquery
function verificatecidosgrupos(empresatecidoid) {
//debugger;
var url = base_url + "home/verificatecidosgrupos";
$.post(url, {grupoT: empresatecidoid},
function (session_gemp) {
//alert(session_gemp);
$('.tecidos option').remove();
$('.tecidos').append("'<option>--Selecione o Tecido--</option>'");
$('.tecidos').append("'" + session_gemp + "'");
});
}
-> html
<td>
<div class="form-group">
<div class="col-sm-9">
<select class="form-control gtecidos" id="gtecidos" name="gtecidos" onchange="carregaid(this.value);verificatecidosgrupos(this.value)" style="width: 70px">
</select>
</div>
</div>
->html
<td>
<div class="form-group">
<div class="col-sm-9">
<select class="form-control tecidos" id="tecidos" name="tecidos" onchange="carregaid(this.value);" style="width: 70px">
</select>
</div>
</div>
I’ll make the changes and test the code and return the information whether or not I got it.
– Anildo Fabiano Alexandre
Worked perfectly.
– Anildo Fabiano Alexandre
Nice young man! D
– Sam