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 :

[DOM] un tableau de checkbox


Sujet :

JavaScript

  1. #1
    Membre régulier
    Inscrit en
    Avril 2007
    Messages
    233
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Avril 2007
    Messages : 233
    Points : 94
    Points
    94
    Par défaut [DOM] un tableau de checkbox
    salut,

    je veux q'une fois je coche un checkbox, toute la ligne de checkbox prend une couleur, ça veux dire que tous le td où se trouve ce checkbox prend une couleur différente..

    Merci
    Il faut parfois servir pour mieux dériger..

  2. #2
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 637
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 637
    Points : 66 662
    Points
    66 662
    Billets dans le blog
    1
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    onmouseup="this.parentNode.parentNode.style.backgroundColor=(this.checked)?'red':'white';"
    Ma page Developpez - Mon Blog Developpez
    Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
    Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
    Votre post est résolu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de Développez !

  3. #3
    Membre régulier
    Inscrit en
    Avril 2007
    Messages
    233
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Avril 2007
    Messages : 233
    Points : 94
    Points
    94
    Par défaut
    S'il vous j'aimerai quelque chose de plus sinificative

    Merci d'avance
    Il faut parfois servir pour mieux dériger..

  4. #4
    Expert confirmé
    Avatar de javatwister
    Homme Profil pro
    danseur
    Inscrit en
    Août 2003
    Messages
    3 681
    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 681
    Points : 5 221
    Points
    5 221
    Par défaut
    oui c'est vrai t'abuses, là!

  5. #5
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 637
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 637
    Points : 66 662
    Points
    66 662
    Billets dans le blog
    1
    Par défaut
    Pfff ... ils ne font vraiment plus aucun effort

    Bon je suis de bonne humeur et voilà ce que ça peut donner :

    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
    <script type='text/javascript'>
     
    function highlightLine(obj){
     
     setTimeout(function(){ if(obj.parentNode.parentNode.colored==undefined){obj.parentNode.parentNode.colored=0;}
     							obj.parentNode.parentNode.colored+=(obj.checked)?1:-1;
     							if (obj.parentNode.parentNode.colored==0){obj.parentNode.parentNode.style.backgroundColor='white';
                                                return true;} 
                            else{obj.parentNode.parentNode.style.backgroundColor=((obj.checked=='false')&&(obj.backgroundColor!='red'))?'white':'red';}
                            	}
                            	,100)
    	}
    	</script>
    </head>
     
    <body>
     
    <table border="1" width="100%">
      <tr>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="12%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
      </tr>
      <tr>
        <tr>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="12%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
      </tr>
      </tr>
      <tr>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="12%">&nbsp;</td>
      </tr>
    </table>
     
    </body>
     
    </html>
    arf juste un detail à regler si click trop rapides ...
    en fait on doit pouvoir virer le setTimeout
    Ma page Developpez - Mon Blog Developpez
    Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
    Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
    Votre post est résolu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de Développez !

  6. #6
    Membre régulier
    Inscrit en
    Avril 2007
    Messages
    233
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Avril 2007
    Messages : 233
    Points : 94
    Points
    94
    Par défaut
    Merci bcp SpaceFrog, au fait je ne voulais pas tout le code, juste des petites explications parce que DOM c'est pas mon point fort!!

    Merci, espérant que tu resteras tjrs en bonne humeur.
    Il faut parfois servir pour mieux dériger..

  7. #7
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 637
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 637
    Points : 66 662
    Points
    66 662
    Billets dans le blog
    1
    Par défaut
    Bon voilà le souci des doubles et triples et multiclicks résolu :

    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
    <script type='text/javascript'>
    var clicked=false;
    function highlightLine(obj){
     if(clicked){return true;}
     clicked=true;
     if(obj.parentNode.parentNode.colored==undefined){obj.parentNode.parentNode.colored=0;}
     obj.parentNode.parentNode.colored+=(obj.checked)?1:-1;
     if (obj.parentNode.parentNode.colored==0){obj.parentNode.parentNode.style.backgroundColor='white';
                                               clicked=false;
                                                return true;} 
     else{obj.parentNode.parentNode.style.backgroundColor=((obj.checked=='false')&&(obj.backgroundColor!='red'))?'white':'red';}
     clicked=false;
                            	}
     
    	</script>
    </head>
     
    <body>
     
    <table border="1" width="100%">
      <tr>
        <td width="11%"><input type="checkbox" onmousedown="highlightLine(this)" ondblclick='return false;'></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)" ondblclick='return false;'></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)" ondblclick='return false;'></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)" ondblclick='return false;'></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="12%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
      </tr>
      <tr>
        <tr>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="11%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
        <td width="12%"><input type="checkbox" onmouseup="highlightLine(this)"></td>
      </tr>
      </tr>
      <tr>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
        <td width="12%">&nbsp;</td>
      </tr>
    </table>
    Ma page Developpez - Mon Blog Developpez
    Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
    Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
    Votre post est résolu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de Développez !

  8. #8
    Membre régulier
    Inscrit en
    Avril 2007
    Messages
    233
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Avril 2007
    Messages : 233
    Points : 94
    Points
    94
    Par défaut
    Voici mon bout de 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
    <script type='text/javascript'>
    function highlightLine(obj)
    {
    		var number=0;
    		if(obj.parentNode.parentNode.colored==undefined)
    		{	obj.parentNode.parentNode.colored=0;	}
     		obj.parentNode.parentNode.colored+=(obj.checked)?1:-1;
     		if(obj.parentNode.parentNode.colored==0)
    		{	obj.parentNode.parentNode.style.backgroundColor='white';
            	return true;
    		} 
            else
    		{	obj.parentNode.parentNode.style.backgroundColor=((obj.checked=='true')&&(obj.backgroundColor!='#CCCCCC'))?'white':'#CCCCCC';	}
    		//alert (obj.checked);
    		for (var i=0; i<obj.parentNode.parentNode.length; i++) 
    		{if(obj.parentNode.parentNode.checked==true)
    			alert('ok');
    		}
     
     
    }
     
    </script>
    <style type="text/css">
    <!--
    .Style1 {font-family: "Book Antiqua";font-size: 12px;}
    -->
    </style>
    </head>
     
    <body>
     
    <table border="1" cellpadding="0" cellspacing="0" width="47%">
      	<tr>
      		<td width="11%">
            	<input type="checkbox" id="c1" onclick="highlightLine(this)">
      			<label for="c1"><span class="Style1">Vous avez reçu un nouveau message</span></label>
            </td>
      	</tr>
     	<tr>
    	  	<td width="11%">
            	<input type="checkbox" id="c2" onclick="highlightLine(this)">
    	    	<label for="c2"><span class="Style1">Vous avez reçu un autre nouveau message</span></label>
            </td>
      	</tr>
        <tr>
       		<td width="11%">
            	<input type="checkbox" id="c3" onclick="highlightLine(this)">
       			<label for="c3"><span class="Style1">Vous avez reçu un avant dernier nouveau message</span></label>
            </td>
      	</tr>
        <tr>
       		<td width="11%">
            	<input type="checkbox" id="c4" onclick="highlightLine(this)">
       			<label for="c4"><span class="Style1">Vous avez reçu un dernier nouveau message</span></label>
            </td>
      	</tr>
    </table>
    ça marche parfaitement mais j'avais pas prévue la possiblité de choisir plusieurs ligne en appuyant sur SHIFT + bouton HAUT ou BAS..

    Avez-vous une idée comment je pourrai effectuer ça??

    Merci
    Il faut parfois servir pour mieux dériger..

Discussions similaires

  1. recuperer un tableau de checkbox
    Par jojo22222 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 18/05/2006, 08h43
  2. Récupérer un tableau de checkbox !
    Par SunSyS dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 27/02/2006, 14h36
  3. Tableau de checkbox
    Par rdams dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 29/08/2005, 17h31
  4. récupérer un tableau de checkbox
    Par mr.t dans le forum ASP
    Réponses: 3
    Dernier message: 05/04/2005, 16h11
  5. Style d'une ligne d'un tableau et Checkbox
    Par echecetmat dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 25/01/2005, 15h03

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