0
This select is an ajax, which I then receive and put into a modal. I needed to pass some values by select and then use them in addAtributo function activated by a button click
<select class="form-control selectDropdown" id='listaAtributo'>
<?
foreach ($atributos as $ind => $v) {
?>
<optgroup label="<?= $v['atributo']; ?>">
<option data-chave='<?= $v['atributo'];?>' data-id='<?= $v['id'];?>'><?= $v['valor']; ?></option>
</optgroup>
<? } ?>
</select>
What I’ve tried but not sure, I can only catch the val(). I also tried to pass the values with onChange in select but as the values are within a foreach did not work, only this.value.
function addAtributo() {
var _atributo = $('#listaAtributo').val();
var _id = $('#listaAtributo').attr("id");
var _id = $('#listaAtributo').attr("data-chave");
var _id = $('#listaAtributo').data("chave");
var _listaAtributoChave = $('#listaAtributo').children(":selected").attr("id");
}
How to proceed?
Thank you for your attention