I am trying that when selecting a value of a select, when opening a modal, the value and the text of the select are passed to different inputs. What would be the following:
rut_usu = this input is passed the value of the selected option.
jc = this input is passed the text of the selected option.
The value is correctly passed to the input rut_usu, but not the text to jc, this tells me "undefined". I'm bringing my values from my database.
I put an alert and it throws me all the text of the select
Function of the model showing the data of the select
public function get_usuarios() {
$this->db->select('rut_usu as rut, pnombre as nom,apellido_pa as pat, apellido_ma as mat');
$this->db->from('usuarios');
$this->db->where('id_tip=2');
$this->db->order_by('pnombre', 'asc');
$usuarios = $this->db->get();
if($usuarios->num_rows() > 0 ){
return $usuarios->result();
}
}
The select displayed in the view
<div class="col-md-4">
<div class="form-group">
<label>Jefes de Carrera</label>
<?= form_open(base_url().'mCalendar/get_usuarios'); ?>
<select class="form-control" id="rut_jc" name="rut_jc">
<option>--Seleccione un Jefe de Carrera--</option>
<?php
$this->load->model('mCalendar');
$usuarios = $this->mCalendar->get_usuarios();
foreach($usuarios as $fila){
echo '<option value="'. $fila->rut.'">'. $fila->nom .' '. $fila->pat .' '.$fila->mat.'</option>';
}
?>
</select>
</div>
</div>
Javascript
$("#rut_jc").change(function(){
var op=document.getElementById("rut_jc");
var tt=document.getElementById("rut_usu");
var jc=document.getElementById("jc");
//alert($("#rut_jc").text());
if (op.selectedIndex > 0)tt.value= op.value ;
if (op.selectedIndex > 0)jc.value= op.text ;
});