1
In this form:
<input type="checkbox" value="1" data-id=1" name="status_entrega" id="status_entrega">
<div id="retorno_1" style="display:none; float:left">Atualizado</div>
<input type="checkbox" value="1" data-id=2" name="status_entrega" id="status_entrega">
<div id="retorno_2" style="display:none; float:left">Atualizado</div>
I got the following jQuery:
$('#status_entrega').click(function(){
var id_pedido = $("#status_entrega").attr("data-id");
$("#retorno_"+id_pedido).toggle(this.checked);
});
However, the first item I can mark as checked, the second and the others, I can’t even check... Does not return the update message. Someone can help?
Updating:
As Sergio help, I modified, but I need to, when unchecking, also send the update request. Follow the updated code:
$('[name="status_entrega"]').click(function() {
var id_pedido = $(this).attr("data-id");
$("#retorno_" + id_pedido).toggle(this.checked);
$.ajax({
type: 'post',
url: '../ajax/getTransacaoOK',
success: function (response) {
$("#retorno_" + id_pedido).html("Atualizando...");
setTimeout(function(){
$("#retorno_" + id_pedido).html("Atualizado!");
setTimeout(function(){
$("#retorno_" + id_pedido).html("");
},1000);
},2000);
},
});
});
Perfect solution. Thank you! :)
– Sr. André Baill
I made an adjustment on it, but when click back, it needs to send the action again... example, checked, sent action, unchecked, sent action again.... but when unchecking, do not send, updated my code.
– Sr. André Baill
@Andrébaill does, but it’s hidden. But to make it even better, you could do it like this: https://jsfiddle.net/m443k17f/
– Sergio
Ok, then I pass the order id, I do inside ajax... date: id_request? :)
– Sr. André Baill
@Andrébaill
data: {id_pedido: id_pedido}
– Sergio
In this case @Sergio, I will send 1 if it is active and 0 is inactive, so I need to pass what is the value of the checkbox?
– Sr. André Baill
This var status_delivery = $("status_delivery"). val(); should solve right? Because then I get the value of the checkbox
– Sr. André Baill
@Andrébaill
data: {id_pedido: id_pedido, estado: this.checked},
– Sergio
Ahh cool, right, I’ll try.
– Sr. André Baill