0
I need to make a list of employees who are linked to cost centers and I need to tell you if this employee is leadership within this cost center.
I tried to mount a select and an added checkbox by clicking the +button, but I can’t get the corresponding values with jquery.
Here is the html
<div class="form-group">
<label for="intIdCentroCusto" class="col-lg-2 control-label"></label>
<div class="col-lg-8">
<table class="col-lg-12 col-md-12">
<tr ><td class="bd_titulo" width="10">Centro de Custo</td><td class="bd_titulo">Liderança</td></tr>
<tr class="linhas" style="width: 800px">
<td style="width: 2000px">
<select data-minlength-error='Selecione pelo menos um'
data-placeholder='Digite ou selecione' data-minlength='1'
multiple='multiple' name='arrCentroCusto[]'
id='arrCentroCusto'
class="js-basic-multiple form-control" required>
<option value="1">Centro custo 1</option>
<option value="2">Centro custo 2</option>
<option value="3">Centro custo 3</option>
</select>
</td>
<td style="width: 300px">
<div class="checkbox">
<label>
<input name='boolLideranca[]' value='1' <?php echo $this->modelo->boolLideranca==1 ? 'checked' : ''; ?> type="checkbox" class="boolLideranca"> Sim
</label>
</div>
</td>
<td><a href="#" class="removerCampo" title="Remover linha"><img src="imagens/details_close.png" border="0" /></a></td>
</tr>
<tr><td colspan="4">
<a href="#" class="adicionarCampo" title="Adicionar item"><img src="imagens/details_open.png" border="0" /></a>
</td>
</table>
</div>
and here I am trying to get the variables with jquery
var lideranca = [] ; // inicia o array;
var arrCentroCusto = []; // inicia o array
b = 0;
i = 0; // ÍNDICE INICIAL DO ARRAY
$('#arrCentroCusto option:selected').each(function() {
arrCentroCusto[i] = $(this).val(); // PEGANDO OS IDS DAS OPÇÕES SELECIONADAS
i++; // INCREMENTANDO O ÍNDICE
});
$(".boolLideranca:checked").each(function() {
lideranca[b] = $(this).val(); // PEGANDO OS IDS DAS OPÇÕES SELECIONADAS
b++;
});
I need to take this information to save on the table the cost center and if it is leadership.
where is the code that adds the elements by clicking on the "+"? Your selector to find the selected items is starting with id ("#arrCentroCusto"), as you can only have one element with this ID, as you will check the others
select
? wouldn’t it be better to use a class for this? Why ID will only read the first– Ricardo Pontual
There are ecrita errors in your Html, select has not been closed.
– LeAndrade
This is not the original code, the original is closed and within a php, I just put an example there.
– Jonathan Augusto Halberstadt
I put the . arrCentroCusto and still only search 1 value
– Jonathan Augusto Halberstadt
Why I need to tell leadership by cost center and not in general. @Diogo
– Jonathan Augusto Halberstadt