Richard Bruno
navigation
Home
admin









HTML - Javascript - PHP
October 18th, 2016

Vérification des cases à cocher (checkbox)



Formulaire de saisie


[...]
<script type="text/javascript">

function tst_cbx(max)
{

result=false;
for (i=0; i<max; i++)
{

name="cbx"+i;
if(document.getElementById(name).checked)
{

result=true;
break;

}

}
if (!result) {alert("Choisissez au moins un public SVP !");};
return result;

}
</script>
[...]
<?php

$sql = "SELECT * FROM publics";
$query = mysql_query($sql) or die ("Requête incorrecte");
$result = mysql_numrows($query);

?>

<form name="article" onsubmit="return tst_cbx('<?php echo $result ?>')" action="enregistrement_article.php" enctype="multipart/form-data" method="post">

<input type="hidden" name=nbpublics value="<?php echo $result ?>">

<?php

if ($result>0) {

$cpt=0;
while ($row = mysql_fetch_array($query"> {

if (strcmp($row["libelle"],"etudiants") == 0)
{

print "<input type="checkbox" name="cbx".$cpt."" value="".$row["index"]."" id="cbx".$cpt."" checked>".htmlentities($row["libelle"], ENT_QUOTES)."<br>";

}
else
{

print "<input type="checkbox" name="cbx".$cpt."" value="".$row["index"]."" id="cbx".$cpt."" >".htmlentities($row["libelle"], ENT_QUOTES)."<br>";

}

$cpt++;
}

}

?>



Récupération des infos


$result = $_POST[nbpublics];
print "nb publics : ".$result."<br>";
//while ($row = mysql_fetch_array($query"> {
for($cpt=0;$cpt < $result;$cpt++) {

$lib = 'cbx'.$cpt;
print "lib : ".$lib."<br>";
if (isset($_POST[$lib]">
{

$public = $_POST[$lib];
print "lib ".$lib." set. valeur : ".$public."<br>";
$sql = "insert into `publics-articles` (`index-articles`, `index-publics`) values ('$index', '$public')";
$query2 = mysql_query($sql) or die ("Erreur 36 - Requête insert incorrecte");

}

}



Dernières modifs
Drupal Multisites - version 6.19 (October 18th, 2016)
Firefox (October 18th, 2016)
HTML - Javascript - PHP (October 18th, 2016)
Kure (October 18th, 2016)
MediaWIKI (October 18th, 2016)
Apache 2 (October 18th, 2016)

Contact
Pour m'envoyer un mail,
Pour me laisser un commentaire :
richard.brunooo
chez
gmail.com


powered by kure, modified by Bruno