Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    Jquery Ajax passsare più checkbox

    Tramite jQuery e Ajax al click sul bottone con classe select vorrei passare a php tutte le checkbox con classe .mycheck selezionate
    Codice PHP:
    jQuery(document).ready(function() {
      
    jQuery('.select').live('click',function() {    
      var 
    mycheck = new Array();    
    jQuery(".mycheck:checked").each(function() {
    var 
    checked_status jQuery('.mycheck').checked;
        if(
    checked_status==true)
           {  
    mycheck.push(jQuery(this).val());    }
    });
    jQuery.ajax({
    type'POST',
        
    urlcontrollo.php',
        data:'
    select'+mycheck,
        success: function(response){
        jQuery('
    .table').replaceWith(response)
                     });
               }
          });
    }); 

  2. #2
    Insomma..
    Dopo il click su un bottone vorrei salvare le checkbox selezionare di un div con determinata classe e inserire i loro valori in una variabile che poi usero in php.

  3. #3
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Prova a cambaire questo blocco:
    codice:
    var mycheck = new Array();     
    jQuery(".mycheck:checked").each(function() { 
    var checked_status = jQuery('.mycheck').checked; 
        if(checked_status==true) 
           {  mycheck.push(jQuery(this).val());    } 
    });
    con questo
    codice:
    var box = new Array();     
    jQuery(".mycheck").each(function() { 
    var checked_status = jQuery('.mycheck').is(':checked'); 
        if(checked_status==true) 
           {  box.push(jQuery(this).val());    } 
    });
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  4. #4
    Ho aggiunto la chiamata ajax cosi
    Codice PHP:
    jQuery('.select').live('click',function() {
    var 
    box = new Array();
    jQuery(".mycheck").each(function() {
    var 
    checked_status jQuery('.mycheck').is(':checked');
    if(
    checked_status==true)
    {  
    box.push(jQuery(this).val()); alert(box);  }                      });
    $.
    ajax({
    type'POST',                         
    url'file.php',
    data'select='+box
    success: function(response){ 
    jQuery('.body').after(response);
    }
    })
    }); 
    Il file php è cosi
    Codice PHP:
    if(isset($_POST['select']))
    {
        
    $file explode(','$_POST['select']);
        
    $select =$file[1];
    }
    echo 
    $select
    Non mi stampa nulla a video.
    Dove sbaglio?

  5. #5
    Originariamente inviato da lucavalentino
    Ho aggiunto la chiamata ajax cosi
    Codice PHP:
    jQuery('.select').live('click',function() {
    var 
    box = new Array();
    jQuery(".mycheck").each(function() {
    var 
    checked_status jQuery('.mycheck').is(':checked');
    if(
    checked_status==true)
    {  
    box.push(jQuery(this).val()); alert(box);  }  });
    $.
    ajax({
    type'POST',                         
    url'file.php',
    data'select='+box
    success: function(response){  jQuery('.body').after(response);  }
    })
    }); 
    Il file php è cosi
    Codice PHP:
    if(isset($_POST['select']))
    {    
    $file explode(','$_POST['select']);   $select =$file[1];    }
    echo 
    $select
    Ho riscritto da zero tutto il codice e parzialemnte funziona.
    Se seleziona almenno 1 una checkbox l'array box registra anche le checkbox non selezionate.
    Se non seleziono nessuna checkbox tutto ok.

  6. #6
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    prova cosi
    codice:
    var box = new Array();     
    jQuery(".mycheck").each(function() { 
    var checked_status = jQuery(this).is(':checked'); 
    alert(checked_status)
        if(checked_status) 
           { box.push(jQuery(this).val());    } 
    alert(box)
    });
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  7. #7
    Grazie cavicchiandrea.
    Voi moderati avete sempre la risposta pronta.
    Alla prossima.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.