IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

integration de script "tout cocher" php / javascript


Sujet :

JavaScript

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 11
    Par défaut integration de script "tout cocher" php / javascript
    Bonjour je voudrais utiliser un script permettant de tout cocher ou tout decocher mes checkbox, le script je l'ai et il fonctionne sur un modele simple, mais je n'arrive cependant pas a l'adapter avec mon code php si quelqu'un pouvait m'aider..

    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
      <meta content="text/html; charset=ISO-8859-1"
     http-equiv="content-type">
      <title></title>
     
    <script type="text/javascript">
    <!--
     
    // choix = '0' pour tout décocher
    // choix = '1' pour tout cocher
    // choix = '2' pour inverser la sélection
     
    function GereChkbox(conteneur, choix) {
    var blnEtat=null;
    var Chckbox = document.getElementById(conteneur).firstChild;
    	while (Chckbox!=null) {
    		if (Chckbox.nodeName=="INPUT")
    			if (Chckbox.getAttribute("type")=="checkbox") {
    				blnEtat = (choix=='0') ? false : (choix=='1') ? true : (document.getElementById(Chckbox.getAttribute("id")).checked) ? false : true;
    				document.getElementById(Chckbox.getAttribute("id")).checked=blnEtat;
    			}
    		Chckbox = Chckbox.nextSibling;
    	}
    }
    //-->
    </script>
     
    </head>
    <body>
     
    <?php
     
            require('connectionBD.php');
     
    //-----------------------------------------------------------------------------------------------
    function select_entreprises($code)
    {
    connection();
    $result = mysql_query("select * from entreprises where id_entreprise = $code");
    return $result;
    };
    //-----------------------------------------------------------------------------------------------
      echo"<form action=traitement_doublons2_E.php method=POST>";
     
             if (isset($_POST['bouton'])) 
        {
            for ($i = 0, $c = count($_POST['bouton']); $i < $c; $i++) 
            {
                $res = select_entreprises($_POST['bouton'][$i]);
                            $r = mysql_fetch_array($res);
                echo "
                            <tr>
                            <td><input type='button' value='Tout selectioner' onClick='GereChkbox('div_chck','1');'></td>
                            <td><input type='button' value='Deselectioner' onClick='GereChkbox('div_chck','0');'></td>
                            <div id='div_chck'>
                            <td><input type='radio' name='bouton' value = '".$r[0]."' id='bouton' /></td>
                <td><input type='hidden' name='id_entreprise$i' value = '".$r[0]."' id='id_entreprise$i' /><label for='id_entreprise$i'>$r[0]</label></td>
                <td><input type = 'checkbox' name='checkbox1' id='checkbox1'  value = '".$r[1]."'></input><label for='code_entreprise'>$r[1]</label></td>
                <td><input type = 'checkbox' name='checkbox2' id='checkbox2'  value = '".$r[2]."'><label for='nom'>$r[2]</label></td>
                <td><input type = 'checkbox' name='checkbox3' id='checkbox3'  value = '".$r[3]."'><label for='adr_rue'>$r[3]</label></td>
                <td><input type = 'checkbox' name='checkbox4' id='checkbox4'  value = '".$r[4]."'><label for='adr_compl'>$r[4]</label></td>
                <td><input type = 'checkbox' name='checkbox5' id='checkbox5'  value = '".$r[5]."'><label for='adr_cp'>$r[5]</label></td>
                <td><input type = 'checkbox' name='checkbox6' id='checkbox6'  value = '".$r[6]."'><label for='adr_ville'>$r[6]</label></td>
                <td><input type = 'checkbox' name='checkbox7' id='checkbox7'  value = '".$r[7]."'><label for='adr_pays'>$r[7]</label></td>
                <td><input type = 'checkbox' name='checkbox8' id='checkbox8'  value = '".$r[8]."'><label for='tel'>$r[8]</label></td>
                <td><input type = 'checkbox' name='checkbox9' id='checkbox9'  value = '".$r[9]."'><label for='fax'>$r[8]</label></td>
                            </tr>";
     
            };
         };
      
                    echo' <br /><br />
                              </table>
                              <input type=submit name="mofidier" value="modifier" />
                              </div></form>';
    ?>
     
    </body>
    </html>
    quelqu'un a une idée ??

    Merci d'avance

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonjour,

    Avec ton code, tu auras plusieurs éléments avec les mêmes id (exemple le div 'div_chck'). Un Id doit être unique dans un document.
    Sinon, montre nous le code html généré mais pas le php.

    A+.

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 11
    Par défaut
    Code html : 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
    		<table border=2 ><tr>
    			<td><input type='button' value='Tout selectioner' onClick='GereChkbox('div_chck','1');'></td>
    			<td><input type='button' value='Deselectioner' onClick='GereChkbox('div_chck','0');'></td>
    			<div id='div_chck'>
    			<td><input type='radio' name='bouton' value = '".$r[0]."' id='bouton' /></td>
                <td><input type='hidden' name='id_entreprise$i' value = '".$r[0]."' id='id_entreprise$i' /><label for='id_entreprise$i'>$r[0]</label></td>
                <td><input type = 'checkbox' name='checkbox1' id='checkbox1'  value = '".$r[1]."'></input><label for='code_entreprise'>$r[1]</label></td>
                <td><input type = 'checkbox' name='checkbox2' id='checkbox2'  value = '".$r[2]."'><label for='nom'>$r[2]</label></td>
                <td><input type = 'checkbox' name='checkbox3' id='checkbox3'  value = '".$r[3]."'><label for='adr_rue'>$r[3]</label></td>
                <td><input type = 'checkbox' name='checkbox4' id='checkbox4'  value = '".$r[4]."'><label for='adr_compl'>$r[4]</label></td>
                <td><input type = 'checkbox' name='checkbox5' id='checkbox5'  value = '".$r[5]."'><label for='adr_cp'>$r[5]</label></td>
                <td><input type = 'checkbox' name='checkbox6' id='checkbox6'  value = '".$r[6]."'><label for='adr_ville'>$r[6]</label></td>
                <td><input type = 'checkbox' name='checkbox7' id='checkbox7'  value = '".$r[7]."'><label for='adr_pays'>$r[7]</label></td>
                <td><input type = 'checkbox' name='checkbox8' id='checkbox8'  value = '".$r[8]."'><label for='tel'>$r[8]</label></td>
                <td><input type = 'checkbox' name='checkbox9' id='checkbox9'  value = '".$r[9]."'><label for='fax'>$r[8]</label></td>
    			</tr>";
     <br /><br />
    </table>
    <input type=submit name="mofidier" value="modifier" />
    </div></form>';

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Re,

    C'est le code source que tu trouves dans ton navigateur
    Lance la page dans ton navigateur et regarde le code qu'il affiche mas pas le php, c'est ça qu'on veut.

    A+.

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 11
    Par défaut
    j'ai juste sa, le javascript n'apparait pas..

    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <FRAMESET BORDER=1>
    <FRAME SRC="frame_centre.html" NAME="bas">
    </FRAMESET>
     
    <head>
      <meta content="text/html; charset=ISO-8859-1"
     http-equiv="content-type">
      <title></title>
    </head>
    <body>
     
    </body>
    </html>

  6. #6
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Billets dans le blog
    20
    Par défaut
    Au moins, ton code a une qualité : il est rigolo

    Bon, en dehors de la syntaxe fantaisiste, à quel moment interviennent tes input
    Parce que j'ai du mal à voir comment, avec une frame en .html tu peux te retrouver avec du code php
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 11
    Par défaut
    j'affiche mes pages php dans une frame en html, donc sur chaque lien, la page est la meme mais n'affiche pas les meme infos, donc mes input interviennent dés lors que j'ai cliquer sur un bouton affichant le tableau

  8. #8
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Billets dans le blog
    20
    Par défaut
    Ah... d'accord, le code au-dessus n'a donc aucun rapport avec ton problème ?
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  9. #9
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 11
    Par défaut
    On m'as demandé d'afficher le code source, donc je l'affiche

  10. #10
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Billets dans le blog
    20
    Par défaut
    Ce qu'on te demande, c'est le code HTML généré qui correspond à ton problème, toi tu nous avais donné le code PHP, mais ça n'a pas beaucoup d'utilité puisque JavaScript s'exécute coté client, donc sur le code HTML qui a été créé.
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  11. #11
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Citation Envoyé par darkxel Voir le message
    On m'as demandé d'afficher le code source, donc je l'affiche
    Ton php va générer des code html (tes checkbox), c'est ça ce qu'on veut voir, mais pas n'importe lequel. Si c'est dans un frame, click droite sur le frame et affiche le code source (je ne me souvient pas très bien si c'est comme ça ).

    A+.

  12. #12
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 11
    Par défaut
    click droite sur le frame et affiche le code source (je ne me souvient pas très bien si c'est comme ça
    lorsque je fais sa, sa m'affiche juste sa

    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <FRAMESET BORDER=1>
    <FRAME SRC="frame_centre.html" NAME="bas">
    </FRAMESET>
     
    <head>
      <meta content="text/html; charset=ISO-8859-1"
     http-equiv="content-type">
      <title></title>
    </head>
    <body>
     
    </body>
    </html>

  13. #13
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Ce code affiche des checkbox


  14. #14
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 11
    Par défaut
    oui ....

  15. #15
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Installe Firebug et montre nous ce qu'il donne

  16. #16
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 11
    Par défaut
    firebug m'affiche

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title></title>
    </head>
    <frameset border="1">
    <frame name="bas" src="frame_centre.html">
    </frame>
    </frameset>
    </html>

  17. #17
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Re

    Essaie d'incrémenter l'id de ton div
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     echo "
    			<tr>
    			<td><input type='button' value='Tout selectioner' onClick='GereChkbox('div_chck".$i."','1');'></td>
    			<td><input type='button' value='Deselectioner' onClick='GereChkbox('div_chck".$i."','0');'></td>
    			<div id='div_chck".$i."'>

    A+.

  18. #18
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 11
    Par défaut re
    re

    j'ai essayé ceci, et malheuresement sa ne fonctionne toujours pas et le javascript n'apparait toujours pas dans firebug..

  19. #19
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    As-tu lu le tutoriel sur Firebug pour inspecter le code source

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo