Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/12/2017, 12:11
Avatar de ArturoGallegos
ArturoGallegos
Moderador
 
Fecha de Ingreso: febrero-2008
Ubicación: Morelia, México
Mensajes: 6.774
Antigüedad: 16 años, 1 mes
Puntos: 1146
Respuesta: Evento onclick en CHECKBOX que solo entra al segundo

ciertamente tienes error de concepto, no te funciona porque metes dentro de addEventListener la llamada ajax

ese esta fuera de lugar, prueba retirandolo y la funcion ajax sacandola... algo asi

Código Javascript:
Ver original
  1. function ajax(url){
  2.     var xhr = window.XMLHttpRequest ?
  3.   new XMLHttpRequest() :
  4.   new ActiveXObject("Microsoft.XMLHTTP") ||
  5.   new ActiveXObject("Msxml2.XMLHTTP");
  6.  
  7.   xhr.open("GET", url, true);
  8.   xhr.send(null);
  9. };
  10.  
  11. function guardar_confirmar() {
  12.     alert("dentro");
  13.   var checkbox = document.getElementById("confirmar"),
  14.     var estado = this.checked ? 1 : 0, //Si está marcado, asigno 1 a 'estado', si no, 0
  15.   id = this.getAttribute("data-id"), //El valor del pseudo-atributo 'data-id'
  16.   url = "/admin/editar-detalle-cobro.php?estado=" + estado + "&idcheckbox=" + id + "&confirmar=1" + "$id=";
  17.   alert(url);
  18.   ajax(url); //Ejecuto la petición asíncrona, enviando los valores
  19. }