2
I have two selects, one for the employee and one for the function, where it is necessary that when an employee is selected the function of the employee is already automatically selected.
That one alert works perfectly, but I need it to be a code to select a option of select of functions in accordance with the data-funcao of the selected employee.
$('#funcionario').on('change', function() {
alert($("option:selected", this).attr('data-funcao'));
});
Select of employees:
<select id="funcionario" name="funcionario">
<option value="..." data-funcao="...">...</option>
...
</select>
Function select:
<select id="id_mfuncao" name="id_mfuncao">
<option value="...">...</option>
...
</select>
I’m using the jquery plugin Select2, I don’t know if it influences anything...
Forehead
$('#id_mfuncao').select2('val', $("option:selected", this).attr('data-funcao'));in place of Alert. I think this is it. It tests and says here.– Sergio
Po did work @Sergio, vlw!
– Raylan Soares
Does anyone know how to do without jQuery?
– Albanir Neves