0
I have a function that searches the bank for an entity list and shows in select. However, I need this same list to be shown at checkbox where the user can check more than one option.
How to show this list of results in < input type="checkbox" name="" value=""id"">?
How to pick up the marked values in Submit?
Current JS mounts the list to a < Select >, need to replace to check:
function CarregaEntrada() {
$.ajax({
url: "/Qualidade/Entidade/CarregaEntidade",
//data: { representante: representante },
async: false,
success: function (data) {
$("#entrada").empty();
$("#entrada").append('<option value="0" disabled selected hidden>Selecione...</option>');
$.each(data, function (i, element) {
$("#entrada").append('<option value=' + element.Id + '>' + element.Descricao + '</option>');
});
}
});
}
});
current html- (need to replace select by check)
<div class="col-md-10">
<select class="form-control select2" id="entrada" name="entrada"></select>
</div>
puts an id in the div for ease, for example "split" and changes the command inside the
each
for:$('#divEntradas').append('<input type="checkbox" name="entrada" id="' + element.Id +'" />' + element.Descricao);
, now to add thechecked
you need some property in return telling if you are selected.– Ricardo Pontual
opa.. I’ll try your suggestion
– Danielle Arruda torres
@Ricardopunctual It worked. Thank you.. Now could you help me by guiding me on how to get the selected items in the form submission? - put in the answer and I mark as the right.
– Danielle Arruda torres
Yes, how is the data you need to go through ajax? an array of numbers, a string..?
– Ricardo Pontual
@Ricardopunctual I will pass by AJAX the form and for each selected item, it will be an Insert in a table where it will contain the form ID and the Entity ID (1 :N ). The same form can have several entities.
– Danielle Arruda torres
posted as an answer to make it easier to visualize
– Ricardo Pontual