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 :

[JavaScript] Problème cocher/décocher checkbox


Sujet :

JavaScript

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Février 2005
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 26
    Par défaut [JavaScript] Problème cocher/décocher checkbox
    Bonjour,

    Voilà j'ai un page générée avec PEAR qui contient:
    - Un formulaire avec :
    1) deux input type button
    2) un submit

    - Un tableau qui me liste des messages avec leur id et leur type et pour chaque ligne un checkbox.

    Mais le tableau ne fait pas parti du formulaire !!! et donc les checkbox non plus !!!

    Voici mon code :
    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
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
     
    /**
    * Template
    */
    	$tpl =& new HTML_Template_Sigma($TPL);
    	$tpl->loadTemplateFile('T_ListeMsg.tpl'); // false pour ne pas retirer les "{" et les "}" pour les templates
    	$renderer =& new HTML_QuickForm_Renderer_ITStatic($tpl);
    	$renderer->setRequiredTemplate('{label}<font color="red" size="1">*</font>');
    	$renderer->setErrorTemplate('<font color="red">{error}</font><br />{html}');
     
    /**
    * JavaScript
    */
     
    $S_JS = "<script type='text/javascript'>
     
    			var checkflag = 'false';
     
    			function toutCocher(){
     
    				if (checkflag == 'false') {
     
    					for (i = 0; i < document.forms['Msg'].length; i++) {
    					  document.forms['Msg'][i].checked = true;
    					}
    					checkflag = 'true';
    				}
    			}
     
    			function toutDecocher(){
     
    			 	if (checkflag == 'true'){
     
    					for (i = 0; i < document.forms['Msg'].length; i++) {
    				  		document.forms['Msg'][i].checked = false; 
    					}
    				  	checkflag = 'false';
    				}
    			}
     
    		</script>";
     
    /**
    * Formumlaire
    */
    	$form = new HTML_QuickForm('FormListeMsg','post');
    	$form->addElement('header', 'titre', Trad2::getLibelle(1769));
    	$form->addElement('button', 'cocher','Tout cocher', array('OnClick'=>'toutCocher()'));
    	$form->addElement('button', 'decocher','Tout décocher', array('OnClick'=>'toutDecocher()'));
    	$form->addElement('submit', 'Suppr','Supprimer');
     
    /**
    * Tableau
    */
    	$table = new HTML_Table (array('border'=>'0','cellpadding'=>'2', 'cellspacing'=>'0', 'class'=>'border-table', 'id'=>'sortable'));
    	$table->setHeaderContents(0, 1, 'Id');
    	$table->setHeaderContents(0, 2, Trad2::getLibelle(17));
    	$table->setHeaderContents(0, 3, Trad2::getLibelle(1770));
     
    /**
    * Requêtes permettant de remplir le tableau
    */
    	global $dbwibux;
    	require_once 'Connection/F_connectionWibux.php';
     
    	// Liste les Libellés inutilisés
    		$S_sqlLib  = 'SELECT numElmnt, tradMsg FROM TradLibelle2 WHERE numElmnt NOT IN (SELECT numElmnt FROM CheminLibelle) AND numLangue=1';
     
    	// Liste les Erreurs inutilisés
    		$S_sqlErr  = 'SELECT numElmnt, tradMsg FROM TradErreur2 WHERE numElmnt NOT IN (SELECT numElmnt FROM CheminErreur) AND numLangue=1';
     
    	$qLib = $dbwibux->query($S_sqlLib);
    	$qErr = $dbwibux->query($S_sqlErr);
     
    	if(DB::isError($qLib)) {
    		trigger_error('Erreur SQL load msg erreur :<br />'.$q->getDebugInfo().'||'.CANNOT_LOAD_MSG, E_USER_ERROR);
    	}
     
    	if(DB::isError($qErr)) {
    		trigger_error('Erreur SQL load msg erreur :<br />'.$q->getDebugInfo().'||'.CANNOT_LOAD_MSG, E_USER_ERROR);
    	}
     
    /**
    * Remplissage du tableau
    */
     
     
    	$I_i = 1;
    	while($rowLib = $qLib->fetchRow()){
    		$Msg = new HTML_QuickForm_checkbox('Msg', $rowLib[0].' TradLibelle2', '', array('id'=>$I_i));
    		$table->setCellContents($I_i, 0, $Msg);
    		$table->setCellContents($I_i, 1, $rowLib[0]);
    		$table->setCellContents($I_i, 2, $rowLib[1]);
    		$table->setCellContents($I_i, 3, 'Libelle');
     
    		$I_i++;
    	}
    	while($rowErr = $qErr->fetchRow()){
    		$Msg = new HTML_QuickForm_checkbox('Msg', $rowErr[0].' TradError2', '', array('id'=>$I_i));
    		$table->setCellContents($I_i, 0, $Msg);
    		$table->setCellContents($I_i, 1, $rowErr[0]);
    		$table->setCellContents($I_i, 2, $rowErr[1]);
    		$table->setCellContents($I_i, 3, 'Erreur');
     
    		$I_i++;
    	}
    print_rn($Msg);	
    	// Effet graphique
    		$altRow1 = array('class'=>'row1','onmouseover'=>'this.style.background=\'#cbcbcb\'', 'onmouseout'=>'this.style.background=\'#fff\'');
    	    $altRow2 = array('class'=>'row2','onmouseover'=>'this.style.background=\'#cbcbcb\'', 'onmouseout'=>'this.style.background=\'#f5f5f5\'');
    	    $table->altRowAttributes(1, $altRow1, $altRow2, true);
     
    /**
    * Affichage du formulaire et du tableau
    */
    	// Formulaire
    		$form->accept($renderer);
    		$tpl->show();
     
    	echo $S_JS;
     
    	echo 'Total : '.$I_i.' message(s)';
     
    	// Tableau
    		echo $table->toHTML();
    En fait la console JavaScript de Firefox m'indique que document.forms.Msg n'a pas de propriétés !!! comprend pas trop

    Est-ce que vous savez comment je pourrai faire pour tous les cocher ou les décocher ?

    Merci d'avance,
    Le_tzao.

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Février 2005
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 26
    Par défaut
    Please Help me !!!!

  3. #3
    Expert confirmé
    Avatar de javatwister
    Homme Profil pro
    danseur
    Inscrit en
    Août 2003
    Messages
    3 684
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : danseur

    Informations forums :
    Inscription : Août 2003
    Messages : 3 684
    Par défaut
    tu serais aimable de nous filer du html/ js plutôt que du php;

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Février 2005
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 26
    Par défaut
    ok désolé je vais dans rubrique php alors (meme si le probleme vient de javascript)

  5. #5
    Expert confirmé

    Avatar de denisC
    Profil pro
    Développeur Java
    Inscrit en
    Février 2005
    Messages
    4 050
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Service public

    Informations forums :
    Inscription : Février 2005
    Messages : 4 050
    Par défaut
    Citation Envoyé par Le_tzao
    ok désolé je vais dans rubrique php alors (meme si le probleme vient de javascript)
    Non, si le problème est un problème JS? c'est le bon forum.

    On te demande juste de nous montrer le code généré par PHP, sous la forme du code de ta page HTML...

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Février 2005
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 26
    Par défaut
    alors voilà le code généré :

    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
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
     
    <form  action="/pages/Trad/F_ListeMsg.php" method="post" name="FormListeMsg" id="FormListeMsg">
    <table>
    	 		<tr>
     
    	 			<td><input onclick="toutCocher()" name="cocher" value="Tout cocher" type="button" /> / <input onclick="toutDecocher()" name="decocher" value="Tout décocher" type="button" /> | </td>
    	 			<td><input name="Suppr" value="Supprimer" type="submit" /></td>
    	 		</tr>
    	 	</table>
    </form>
    <script type='text/javascript'>
     
    			var checkflag = 'false';
     
    			function toutCocher(){
     
    				if (checkflag == 'false') {
     
    					for (i = 0; i < document.forms['Msg'].length; i++) {
    					  document.forms['Msg'][i].checked = true;
    					}
    					checkflag = 'true';
    				}
    			}
     
    			function toutDecocher(){
     
    			 	if (checkflag == 'true'){
     
    					for (i = 0; i < document.forms['Msg'].length; i++) {
    				  		document.forms['Msg'][i].checked = false; 
    					}
    				  	checkflag = 'false';
    				}
    			}
     
    		</script>Total : 632 message(s)<table border="0" cellpadding="2" cellspacing="0" class="border-table" id="sortable">
    	<tr>
     
    		<td>&nbsp;</td>
    		<th>Id</th>
    		<th>Message</th>
    		<th>Type de Message</th>
    	</tr>
    	<tr class="row1" onmouseover="this.style.background='#cbcbcb'" onmouseout="this.style.background='#fff'">
    		<td>			<input id="1" name="Msg" type="checkbox" value="1" /></td>
     
    		<td>2</td>
    		<td>Veuillez corriger ces champs</td>
    		<td>Libelle</td>
    	</tr>
    	<tr class="row2" onmouseover="this.style.background='#cbcbcb'" onmouseout="this.style.background='#f5f5f5'">
    		<td>			<input id="2" name="Msg" type="checkbox" value="1" /></td>
    		<td>1</td>
     
    		<td>Information invalide</td>
    		<td>Libelle</td>
    	</tr>
    	<tr class="row1" onmouseover="this.style.background='#cbcbcb'" onmouseout="this.style.background='#fff'">
    		<td>			<input id="3" name="Msg" type="checkbox" value="1" /></td>
    		<td>5</td>
    		<td>Ensemble de pages</td>
     
    		<td>Libelle</td>
    	</tr>
    	<tr class="row2" onmouseover="this.style.background='#cbcbcb'" onmouseout="this.style.background='#f5f5f5'">
    		<td>			<input id="4" name="Msg" type="checkbox" value="1" /></td>
    		<td>8</td>
    		<td>Le nom de la page est invalide</td>
    		<td>Libelle</td>
     
    	</tr>
    	<tr class="row1" onmouseover="this.style.background='#cbcbcb'" onmouseout="this.style.background='#fff'">
    		<td>			<input id="5" name="Msg" type="checkbox" value="1" /></td>
    		<td>9</td>
    		<td>formulaire de Statistiques</td>
    		<td>Libelle</td>
    	</tr>
     
    	<tr class="row2" onmouseover="this.style.background='#cbcbcb'" onmouseout="this.style.background='#f5f5f5'">
    		<td>			<input id="6" name="Msg" type="checkbox" value="1" /></td>
    		<td>10</td>
    		<td>Veuillez vous connecter !</td>
    		<td>Libelle</td>
    	</tr>
    	<tr class="row1" onmouseover="this.style.background='#cbcbcb'" onmouseout="this.style.background='#fff'">
     
    		<td>			<input id="7" name="Msg" type="checkbox" value="1" /></td>
    		<td>19</td>
    		<td>a bien &eacute;t&eacute; mis &agrave; jour.</td>
    		<td>Libelle</td>
     
    	</tr>
    	<tr class="row2" onmouseover="this.style.background='#cbcbcb'" onmouseout="this.style.background='#f5f5f5'">
    		<td>			<input id="8" name="Msg" type="checkbox" value="1" /></td>
    		<td>20</td>
    		<td>a bien &eacute;t&eacute; enregistr&eacute;.</td>
     
    		<td>Libelle</td>
    	</tr>
    .
    .
    .
    .

  7. #7
    Expert confirmé

    Avatar de denisC
    Profil pro
    Développeur Java
    Inscrit en
    Février 2005
    Messages
    4 050
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Service public

    Informations forums :
    Inscription : Février 2005
    Messages : 4 050
    Par défaut
    Citation Envoyé par Le_tzao
    for (i = 0; i < document.forms['Msg'].length; i++)
    Pas bon ça...

    Utilise le vecteur suivant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    document.forms['FormListeMsg'].elements['Msg']
    Il contient tous les inputs ayant pour nom Msg de ton formulaire FormListeMsg. Dans ton code précédent, il manquait une information.

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Février 2005
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 26
    Par défaut
    ca ne marche pas car les checkbox ne font pas parti du formulaire FormListeMsg !!!

  9. #9
    Expert confirmé
    Avatar de javatwister
    Homme Profil pro
    danseur
    Inscrit en
    Août 2003
    Messages
    3 684
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : danseur

    Informations forums :
    Inscription : Août 2003
    Messages : 3 684
    Par défaut
    et puis comme tu l'avais bien dit au début, tes champs ne sont pas des éléments du formulaire!
    c'est gênant;

  10. #10
    Expert confirmé

    Avatar de denisC
    Profil pro
    Développeur Java
    Inscrit en
    Février 2005
    Messages
    4 050
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Service public

    Informations forums :
    Inscription : Février 2005
    Messages : 4 050
    Par défaut
    Citation Envoyé par Le_tzao
    ca ne marche pas car les checkbox ne font pas parti du formulaire FormListeMsg !!!
    En effet, et ton problème est justement qu'ils ne sont pas dans un formulaire!!!!!

    Les inputs en dehors du formulaire, ça n'existe pas

  11. #11
    Membre averti
    Profil pro
    Inscrit en
    Février 2005
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 26
    Par défaut
    Je sais bien mais PEAR n'accepte pas d'objet tableau dans un formulaire

  12. #12
    Expert confirmé
    Avatar de javatwister
    Homme Profil pro
    danseur
    Inscrit en
    Août 2003
    Messages
    3 684
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : danseur

    Informations forums :
    Inscription : Août 2003
    Messages : 3 684
    Par défaut
    eh oui

  13. #13
    Membre averti
    Profil pro
    Inscrit en
    Février 2005
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 26
    Par défaut
    Comment je peux faire alors ? Vous avez une idée ?

  14. #14
    Expert confirmé

    Avatar de denisC
    Profil pro
    Développeur Java
    Inscrit en
    Février 2005
    Messages
    4 050
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Service public

    Informations forums :
    Inscription : Février 2005
    Messages : 4 050
    Par défaut
    Ne mets pas de tableaux dans ton formulaire?

  15. #15
    Membre averti
    Profil pro
    Inscrit en
    Février 2005
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 26
    Par défaut
    mouais c'est solution ne me convient pas trop mais je crois que j'ai pas le choix !!!! Merci quand même à tous pour votre aide !!!

  16. #16
    Membre Expert
    Inscrit en
    Septembre 2002
    Messages
    2 307
    Détails du profil
    Informations forums :
    Inscription : Septembre 2002
    Messages : 2 307
    Par défaut
    Mais le tableau ne fait pas parti du formulaire !!! et donc les checkbox non plus !!!
    // Tableau
    echo $table->toHTML();
    ->
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    // Tableau 
    echo "<form name='formTab'>"
          echo $table->toHTML(); 
    echo "</form>"
    :

  17. #17
    Membre averti
    Profil pro
    Inscrit en
    Février 2005
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 26
    Par défaut
    Merciiiiiiiiiiiii Bcp bcp bcp bcp bcp bcp bcp bcp bcp !!!! ca marche nickel merci encore et encore et encore et encore et encore !!!!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 9
    Dernier message: 21/12/2009, 11h20
  2. tout cocher/tout décocher checkboxs
    Par Mo_Poly dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 07/11/2007, 21h39
  3. comment cocher/décocher checkbox avec un bouton radio
    Par faucon54 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 29/05/2007, 17h26
  4. Comment cocher/décocher plusieurs "checkbox"?
    Par Crazynoss dans le forum ASP
    Réponses: 2
    Dernier message: 15/05/2005, 23h38
  5. [HTML] [Formulaire] Empêcher de cocher/décocher une checkbox
    Par requiemforadream dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 02/05/2005, 15h46

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