0
When using a javascript function in two populated selects, it overrides the css by hiding its values and assigning another class, as shown below:
Before using the function:
By clicking the first select and choosing an option:
Inspecting the element in the browser:
He assigned the display: none
and used other css classes to make this mess. When using css to assign display: visible !important
it reappears but shows two selects:
I can’t seem to solve:
If necessary I leave the javascript code here!
Javascript code:
$(document).ready(function() {
$(".select1").change(function() {
var proxima_turma = <?php echo json_encode($proxima_turma); ?>;
var antiga_turma = <?php echo json_encode($antiga_turma); ?>;
var valor = $(this).val();
var select = $(this).closest("tr").find(".select2"); // busca o select2 da mesma linha
if (valor == "") {
select
.html("")
.append("<option value=''> Selecione </option>");
} else if (valor == "<?php echo $class_id_to;?>") {
select.html("");
for(var i = 0; i < proxima_turma.length; ++i) {
select.append("<option value='" + proxima_turma[i]['section_id'] + "'>" + proxima_turma[i]['name'] + "</option>");
}
} else if (valor == "<?php echo $class_id_from; ?>") {
select.html("");
for(var i = 0; i < antiga_turma.length; ++i) {
select.append("<option value='" + antiga_turma[i]['section_id'] + "'>" + antiga_turma[i]['name'] + "</option>");
}
}
});
});
Select code:
<select <?php if ((($transferidos != null) && ($evadidos != null)) OR (($transferidos != null) || ($evadidos != null))) ?>
class="form-control selectboxit select2" <?php if (!$disableSelect) { ?>
name="promotion_status2_<?php echo $row['student_id'];?>" style="width: 40px;"
<?php } ?> >
<?php if ((($transferidos != null) && ($evadidos != null)) OR (($transferidos
!= null) || ($evadidos != null))) { ?>
<option value="null" selected></option>
<?php }else{
?>
<option value="">selecione</option>
</select>
Put your javascript too, so we know what he’s doing.
– Maycon F. Castro