0
<script type="text/javascript">
var base_url = '<?=base_url(); ?>';
$(document).ready(function () {
// Evento change
$("select[name=laboratorio]").change(function () {
// Exibimos
//$("select[name=data_prova]").html('<option value="">Carregando datas...</option>');
// Passando tipo por parametro para a pagina
//alert(base_url+$(this).val());
$.post(base_url+"aluno/reserva_av3/busca_data_prova",
{laboratorio: $(this).val()},
// Carregamos o resultado acima para o campo
function (valor) {
$("select[name=data_prova]").html(valor);
}
)
})
});
</script>
with the above function I load the date that is in my view:
<!-- SELECAO DATA -->
<div class="form-group">
<label class="col-md-3 control-label" for="selectbasic">Data da prova:</label>
<div class="col-md-6">
<select id="data_prova" required = "" name="data_prova" class="form-control">
</select>
</div>
</div>
whose controller loads the information:
public function busca_data_prova(){
$this->load->model("aluno/reserva_av3_model");
$data = $this->reserva_av3_model->retorna_data_agendada();
echo $option = "<option value=''>Selecione a data para realizar sua prova</option>";
foreach($data as $linha) {
$datar = $linha->data;
$DT = date("d/m/Y", strtotime($datar));
echo $option = "<option value=".$linha->cod_data.">".$DT."</option>";
}
}
and the model:
public function retorna_data_agendada()
{
$laboratorio = $this->input->post("laboratorio");
$consulta = $this->db->query('
SELECT DISTINCT dbo.P_chekin_Geral.cod_lab, dbo.P_chekin_Geral.al_reg, dbo.P_chekin_Geral.cod_data, dbo.P_checkin_Datas.data, dbo.P_checkin_Datas.dia
FROM dbo.P_chekin_Geral INNER JOIN
dbo.P_checkin_Datas ON dbo.P_chekin_Geral.cod_data = dbo.P_checkin_Datas.cod_data
GROUP BY dbo.P_checkin_Datas.data, dbo.P_chekin_Geral.al_reg, dbo.P_chekin_Geral.cod_data, dbo.P_checkin_Datas.dia, dbo.P_chekin_Geral.cod_lab
HAVING (dbo.P_chekin_Geral.cod_lab = "'.$laboratorio.'") AND (dbo.P_chekin_Geral.al_reg IS NULL)
ORDER BY dbo.P_chekin_Geral.cod_data
');
return $consulta->result();
This is all working, but now what I need is that when I select the date the select option time load with the default bank schedules, only it is not loading see:
the script looks like the previous one:
<script type="text/javascript">
var base_url = '<?=base_url(); ?>';
$(document).ready(function () {
// Evento
$("select[name=data_prova]").change(function () {
// Exibimos
$.post(base_url+"aluno/reserva_av3/busca_horario_agendado",
{data_prova: $(this).val()},
// Carregamos o resultado acima para o campo
function (valor) {
$("select[name=horario_prova]").html(valor);
}
)
})
});
</script>
the view:
<!-- SELECAO HORARIO -->
<div class="form-group">
<label class="col-md-3 control-label" for="selectbasic">Horario da prova:</label>
<div class="col-md-6">
<select id="horaio_prova" required = "" name="horario_prova" class="form-control">
</select>
</div>
</div>
and the controller:
public function busca_horario_agendado(){
$this->load->model("aluno/reserva_av3_model");
$hora = $this->reserva_av3_model->retorna_horario_agendado();
echo $option = "<option value=''>Selecione o horario para realizar sua prova</option>";
foreach($hora as $linha) {
echo $option = "<option value=".$linha->cod_horario.">".$linha->Descricao."</option>";
}
}
the Model:
public function retorna_horario_agendado($turno)
{
$dataprova = $this->input->post("data_prova");
$laboratorio = $this->input->post("laboratorio");
$consulta = $this->db->query('
SELECT DISTINCT dbo.P_chekin_Geral.cod_horario, dbo.P_checkin_Horarios.Descricao, dbo.P_checkin_Horarios.Turno, dbo.P_chekin_Geral.al_reg, dbo.P_chekin_Geral.cod_data
FROM dbo.P_chekin_Geral INNER JOIN
dbo.P_checkin_Horarios ON dbo.P_chekin_Geral.cod_horario = dbo.P_checkin_Horarios.COD_HORARIO
GROUP BY dbo.P_chekin_Geral.al_reg, dbo.P_checkin_Horarios.Descricao, dbo.P_checkin_Horarios.Turno, dbo.P_chekin_Geral.cod_horario, dbo.P_chekin_Geral.cod_lab,
dbo.P_chekin_Geral.cod_data
HAVING (dbo.P_chekin_Geral.al_reg IS NULL) AND (dbo.P_chekin_Geral.cod_lab = "'.$laboratorio.'") AND (dbo.P_chekin_Geral.cod_data = "'.$dataprova.'") AND (dbo.P_checkin_Horarios.Turno = "'.$turno.'")
only that it returns me absolutely nothing, since in the model everything is ok
Hello friend, can you debug your code? to know if you are entering foreach, for example
– Gabriel Santos
I also noticed that in select "proof_horario_proof" the ID and NAME are different, I think that’s not the problem, since you only use the NAME property, but it’s not a good one
– Gabriel Santos
I was able to display without selecting the date, but I need to get the date value to compare in the bank select. I cannot pass this value select[name=data_proof]
– user55375
Try debugging and isolating the error, find out which line it crashes on, if n has a configured Debugger, just try to insert the return URL in the browser(base_url+"student/reserva_av3/search_time_scheduled", replacing the clear base_url), and put the result here as an Edit, so that we can analyze for you
– Gabriel Santos
The controller: public Function busca_horario_scheduled()' $turno = $this->turno; $this->load->model("student/reserva_av3_model"); $hour = $this->reserva_av3_model->return_scheduled($turn); echo $option = "<option value='>Select the time to perform your proof</option>"; foreach($hour as $line) ? echo $option = "<option value=". $line->cod_time." >". $line->Description."</option>"; } }
– user55375
I put the rest of the code up there on the model. the problem is even in the java script function I just need to get the value of the date when selected and ready, but the date I can’t, I can only get the value of the lab
– user55375
if I swap select[name=data_prova] for select[name=laboratorio] and {data_prova: $(this). val()} for {laboratorio: $(this). val()}, ai shows all dates at once, but only want dates that were selected in the previous select.
– user55375
Already got it! Thanks! just add laboratory: $('#laboratorio'). val()
– user55375