bonjour

c'est mon premier post sur ce site que je trouve hyper intéressant.

sujet : j'ai une liste de checkbox que je souhaite sélectionner certaine valeurs et après envoyer vers une page PHP pour traiter.

j'ai créer une fonction pour parcourir le tableau des checkbox et puis un bouton pour envoyer vers la page PHP.

ci-joint le code

merci à vous

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$("#Tableau_ref_total").on('click','tr',function()
            {
                    var coche;
                    var id = $(this);
                    var tableau_ref = [];
                    var txt;
                    var numeroRef = $(this).find("td").eq(0).text();
                       alert(numeroRef);
                    //-- gestion de la ligne -----------------------------------
                    $('.checkbox-ref-Ajout',id).each(function()
                    {
                     if( $(this).is(':checked'))
                        {
                            coche="Cochée";
                            tableau_ref.push(id,coche,txt);
                            //alert(coche);
                        }   
                        else{
                            coche="NonCochée";
                            tableau_ref.pop(id,coche,txt);
                            //alert(coche);
                        }
                    });
            });
//------------------------------------------------------------------------------               
            $("#bt-ajouter-ref").on('click',function()
            {
            var txtCoche = [];
            var action = "Insert";
            var id = "";
            var objNum = $('#Numero').val();
            //------------------------------------------------------------------
                $("#Tableau_ref_total tr").each(function()
                    {
                       id = $(this);
                       var numero = $(this).find("td").eq(0).text();
                       alert(numero);
                       $('.checkbox-ref-Ajout',id).each(function()
                        {
                            if( $(this).is(':checked'))
                            {
                               //alert("vous allez Ajouter le N°:"+numero);
                               txtCoche.push([numero]);
                            }
                        });
                    });
                   //-- Envoi des données vers le sql
                $.post('../Instruction/Sql.php',{txtCoche:txtCoche,action:action,objNum:objNum},function(data)
                    {
                        //alert(txtCoche);
                        //alert(action);
                        //alert(objNum);
                        alert(data);
                    });
            });