Foros del Web » Programando para Internet » Jquery »

[SOLUCIONADO] Problema checkbox repite mensaje box

Estas en el tema de Problema checkbox repite mensaje box en el foro de Jquery en Foros del Web. Probar el siguiente código por favor. Al tildar el CHECKBOX y confirmar con ACEPTAR se elimina el cliente. Todo funciona bien, pero si yo doy ...
  #1 (permalink)  
Antiguo 14/08/2014, 10:38
Avatar de Fernarey1810  
Fecha de Ingreso: noviembre-2008
Mensajes: 214
Antigüedad: 15 años, 5 meses
Puntos: 1
Problema checkbox repite mensaje box

Probar el siguiente código por favor. Al tildar el CHECKBOX y confirmar con ACEPTAR se elimina el cliente. Todo funciona bien, pero si yo doy en cancelar, y luego vuelvo a intentar eliminar el cliente con el CHECBOX miren lo que ocurre. Se empieza a repetir 2 veces el mensaje localhost, luego se repite 3, luego 4, luego 5 etc porque ocurre eso?

Código HTML:
Ver original
  1. <title>Documento sin título</title>
  2. <script type='text/javascript' src='jquery-1.7.2.min.js'></script>
  3. <script type="application/javascript">
  4. function chk_click(id, check) {
  5.     $('input[name=baja]').live("click",function(){
  6.         var id = $(this).attr('id');
  7.        
  8.         var box = confirm("¿Está seguro que desea eliminar el cliente?");
  9.         if (box == true) {
  10.             $.ajax({
  11.                 type:'POST',
  12.                 url:'ajax_chk_cliente.php',
  13.                 data:'id= ' + id,
  14.                 success: function() {
  15.                     window.location.href = "ver_cliente.php";  // = 'ver_cliente.php'; //href
  16.                 }                                                                          
  17.             });
  18.         }else {
  19.             document.getElementById(id).checked = false;
  20.         }                                                                  
  21.     });
  22. }  
  23. </head>
  24.  
  25.  
  26. <form action="" method="post">
  27.     <input type="checkbox" id="1" name="baja" onclick="chk_click('1', 'check');" title="eliminar cliente" />';
  28.     <input type="checkbox" id="2" name="baja" onclick="chk_click('2', 'check');" title="eliminar cliente" />';
  29.     <input type="checkbox" id="3" name="baja" onclick="chk_click('3', 'check');" title="eliminar cliente" />';
  30. </form>
  31.  
  32. </body>
  33. </html>
  #2 (permalink)  
Antiguo 15/08/2014, 09:48
 
Fecha de Ingreso: agosto-2013
Mensajes: 150
Antigüedad: 10 años, 8 meses
Puntos: 29
Respuesta: Problema checkbox repite mensaje box

Creo que sobra código.
Prueba
Código Javascript:
Ver original
  1. $(document).ready(function() {
  2.  
  3.         $('input[name=baja]').on("click", function() {
  4.           var id = $(this).attr('id');
  5.           var box = confirm("¿Está seguro que desea eliminar el cliente?");
  6.           if (box == true) {
  7.             $.ajax({
  8.               type: 'POST',
  9.               url: 'ajax_chk_cliente.php',
  10.               data: 'id= ' + id,
  11.               success: function() {
  12.                 window.location.href = "ver_cliente.php";
  13.               }
  14.             });
  15.           } else {
  16.             $(this).prop('checked', false);
  17.           }
  18.         });
  19.  
  20.       });
y elimina los onclick.
  #3 (permalink)  
Antiguo 19/08/2014, 15:23
Avatar de Fernarey1810  
Fecha de Ingreso: noviembre-2008
Mensajes: 214
Antigüedad: 15 años, 5 meses
Puntos: 1
Respuesta: Problema checkbox repite mensaje box

Muchas gracias ese era el problema.

Etiquetas: ajax, box, checkbox, funcion, html, input, javascript, js, mensaje, php, repite
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:33.