0
I have a form that has a button to mark all checksbox
in a datatable
. So far, so good. What I can’t do is take the value of checkbox
marked and return the value 1
in another input
within the datatable
.
I tried so:
var checkbox = document.getElementsByName('marcar[]');
var cps = document.getElementById("Numbloqueios");
function addCheck() {
var teste = [];
for (var i = 0; i < checkbox.length; i++) {
if (checkbox[i].checked == 0) teste.push(checkbox[i].value);
}
cps.innerHTML = teste.join();
}
HTML:
<div class="col-md-8">
<div class="row">
<div class="col-md-3 col-md-offset-3">
<label for="todos">Selecionar Todos:</label>
<button class='btn btn-large' type='button' title='Todos' id='todos'
onclick='marcardesmarcar();'>
<i class='icon-large icon-ok'>Aperte Aqui</i>
</button>
</div>
<div class="col-md-6">
<label for="salvar">Para Aprovar:</label>
<button class='btn btn-large' type='button' title='salvar' id='salvar' onclick='addCheck()'>
<i class='icon-large icon-ok'>Aperte Aqui</i>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12" data-type="tabledetail" data-show-properties="" data-field-name="Itens2">
<div class="form-input">
<label class="text-danger">Lançamentos</label>
<table tablename="tableItens" class="table table-bordered table-striped" noaddbutton="true">
<thead class="thead-light">
<tr class="active">
<td></td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center; vertical-align:middle">
<div class="col-sm-1" data-type="textbox" data-show-properties=""
data-field-name="checar" id="indexador">
<div class="form-input">
<div class="form-group"></div>
</div>
<input type="checkbox" class="marcar" value ="" id="marcar" name="marcar">
</div>
<td>
good guys I did something wrong using the example of @Danilo Leone, I tried again and made some adaptations, conform below.
<script type="text/javascript">
function get_all_id() {
var checkbox = document.getElementsByClassName('marcar[]');
var cpbloq = document.getElementById('cpnumbloqueios').value;
var cps = document.querySelector('input[name="Numbloqueios"]');
var teste = [];
for (var i = 0; i < checkbox.length; i++) {
if (checkbox[i].checked == 1 && (cpbloq = 1) ) teste.push(checkbox[i].value);
}
cps.innerHTML = teste.join();
console.log(teste);
}
</script>
But the console.log
returns empty.
How is your html?
– edson alves
Checkbox has no value and name should not be marked[]
– Deividson Oliveira
Your HTML code is incomplete. Where are the checkboxes? Where is the "mark"?
– Sam
I edited the question, the checkbox are in a datatable, which is mounted dynamically, as I said, the check button all this ok, that feature I want to deploy would be the approve button all, that so clicking the code would check who is marked and change the value of an input that you like on each datatable ROW.
– Bruno Rayol
I haven’t been able to...
– Bruno Rayol