Bonjour,
j'ai récupérer un script javascript qui me permet de cocher tous les checkboxs present dans un formulaire...j'avoue avoir du mal avec le javascript
voici mon code :
<form action="essai" method="post" name="all_submit">
<table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="1" class="couleurs1">
<img src="../images_site/petites_icones/supprimer.png" alt="Tout supprimer" title="Tout supprimer"/>
</td>
<td width="1" class="couleurs1">ID </td>
<td class="couleurs1">Titre</td>
<td class="couleurs1">Date</td>
<td width="1" class="couleurs1">Online </td>
<td width="1" class="couleurs1">Posteur </td>
<td colspan="3" class="couleurs1">Gestion</td>
</tr>
<tr>
<td width="1" class="couleurs1">
<input type="checkbox" value="Cocher" onClick="this.value=check(this.form.elements['suppbox[]'])"></td>
<td width="1" class="couleurs1"> </td>
<td class="couleurs1"> </td>
<td class="couleurs1"> </td>
<td class="couleurs1">
<div align="center">
<?php
echo alldesactive($online_offline, $chp_page, "Tout Offline", "Tout Online");
?>
</div></td>
<td class="couleurs1"> </td>
<td colspan="3" class="couleurs1"> </td>
</tr>
<?php
while($row_txtacc= mysql_fetch_assoc($sql_acctt))
{
if ($row_txtacc['txtallaccueil_id'] == $editer_accueil)
{
$class = "couleurs3";
$couleurs = $couleurs;
}
elseif ($couleurs == "0")
{
$class = "couleurs1";
$couleurs = "1";
}
else
{
$class = "couleurs2";
$couleurs = "0";
}
///Parametres
$online_offline.= $row_txtacc['txtallaccueil_online'];
?>
<tr>
<form action="index.php?page=0" method="post" name="valider">
<td class="<?php echo $class; ?>">
<input name="suppbox[]" type="checkbox" id="suppbox[]" value="1" />
</td>
<td class="<?php echo $class; ?>">
<div align="center"><?php echo $row_txtacc['txtallaccueil_id']; ?></div> </td>
<td class="<?php echo $class; ?>">
<input name="txtallaccueil_titre" type="text" value="<?php echo stripslashes($row_txtacc['txtallaccueil_titre']); ?>" size="35" /> </td>
<td class="<?php echo $class; ?>"><?php echo date('d/m/Y H:m:s',$row_txtacc['txtallaccueil_date']); ?></td>
<td class="<?php echo $class; ?>"><div align="center"><?php echo online($row_txtacc['txtallaccueil_online']); ?></div></td>
<td class="<?php echo $class; ?>"><div align="center"><?php echo posteur($row_txtacc['txtallaccueil_user_id']); ?></div></td>
<td width="1" class="<?php echo $class; ?>">
<input name="txtallaccueil_id" type="hidden" value="<?php echo $row_txtacc['txtallaccueil_id']; ?>" />
<input name="valider" type="hidden" value="accueil" />
<?php echo $chp_page; ?>
<input name="userid" type="hidden" value="<?php echo $_SESSION['cb_user']->userid; ?>" />
<input name="valider" type="button" value="Valider" onclick="submit('valider')"/> </td>
</form>
<td width="1" class="<?php echo $class; ?>">
<form action="index.php?page=<?php echo $_GET['page']; ?>" method="post" name="editer">
<input name="editer_accueil" type="hidden" value="<?php echo $row_txtacc['txtallaccueil_id']; ?>" />
<input name="valider" type="hidden" value="accueil" />
<?php echo $chp_page; ?>
<input name="editer" type="button" value="Editer" onclick="submit('editer')"/>
</form> </td>
<td width="1" class="<?php echo $class; ?>">
<form action="index.php?page=<?php echo $_GET['page']; ?>" method="post" name="supprimer">
<input name="supprimer_accueil" type="hidden" value="<?php echo $row_txtacc['txtallaccueil_id']; ?>"/>
<input name="valider" type="hidden" value="accueil" />
<?php echo $chp_page; ?>
<input name="supprimer" type="button" value="Supprimer" class="bt_supprimer" onclick="submit('supprimer')"/>
</form> </td>
</tr>
<?php
}
?>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="couleurs1">
<input name="tt_supprimer" type="button" value="Tout supprimer" class="bt_supprimer" onclick="submit('all_submit')"/>
</td>
</tr>
</table>
</form>
voici ma fonction javascript :
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Tout décocher"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Tout cocher"; }
}
// End -->
</script>
Ce checkbox :
<input type="checkbox" value="Cocher" onClick="this.value=check(this.form.elements['suppbox[]'])">
permet de cocher tous les autres checkbox :
<input name="suppbox[]" type="checkbox" id="suppbox[]" value="1" />
merci de votre aide !!!