salut a tous,

dans un tableau je désire changé la couleur d'une ligne et en même temps sélectionné le checkbox correspondant par un seule clic
code js
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
/********* colorer une ligne et sélectionner une case lors d'un clic *****/
function tr_select(tr){
var bgcolor = "#FFE8DD";
var change_color = "#940555";
var monform= document.getElementById("myform");
var tr = document.getElementsByTagName("tr");
var td = document.getElementsByTagName("td");
var chk = document.getElementsByName("checkbox[]");
 
for(var i=0;i<chk.length;i++){
if(tr[i]){
k=i;
tr[i+2].style.backgroundColor=change_color;
chk[k].checked=true;
}else{
tr[i+2].style.backgroundColor=bgcolor;
chk[k].checked=false;
}
  }
  }
et le html :
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
<div id="div1">
<form action="delete_mult.php" method="POST" id='myform'>
<table border=1 align='center' id="montab"><tr><thead><th>id</th><th>titre</th><th>new</th><th>
<input type="checkbox" name="checkbox" id="checkbox" onclick="chksel();" />Check/Uncheck(All)</th></thead></tr>
<?php
while($data =mysql_fetch_array($res)){
/*$id=$data['id'];
$title=$data['title'];
$news=$data['news'];
onmouseover='mover(this);' onmouseout='mout(this);' 
*/
extract($data);
echo "<tr name='tr' class='tr' style='background-color:#edeefd;' onclick='tr_select(this);'>
<td name='td'>$id</td>
<td name='td'>$title</td>
<td name='td'>$news</td>"?>
<td><input type="checkbox" name='checkbox[]' value="<?php echo $id;?>" /></td></tr>
<?php
}
?>
<input type='submit' value='supprimer' name='delete' class='button' onclick='supr();' />
</table></form></div>
si quelqu'un peut bien m'aider !!