Ragazzi ho questo codice:
<form method="post" name="mioform" action="cancella_prodotto.php" onsubmit="return controllo_selezione()">
<tr>
<td width="20%" align="center">
<font color="#FFFFFF" face="Tahoma" size="2">Foto</font></td>
<td width="20%" align="center">
<font color="#FFFFFF" face="Tahoma" size="2">Nome</font></td>
<td width="20%" align="center">
<font color="#FFFFFF" face="Tahoma" size="2">Categoria</font></td>
<td width="20%" align="center">
<font color="#FFFFFF" face="Tahoma" size="2">Modifica</font></td>
<td width="20%" align="center">
<font color="#FFFFFF" face="Tahoma" size="2"><input type="button" onclick="javascript: controllo_selezione()" value="Cancella_selezionati" size="20"></font></td>
</tr>
<?
while($dati = mysql_fetch_array($res[0])){
$idprodotto = $dati['id'];
$idcategoria = $dati['idcategoria'];
$querycategoria = "SELECT categoria from categorie where id = $idcategoria";
$esegui = mysql_query($querycategoria) or die(mysql_error());
$row = mysql_fetch_assoc($esegui);
$categoria = $row['categoria'];
?>
<tr>
<td width="20%" align="center">
<font color="#FFFFFF" face="Tahoma" size="2">[img]../public/<?=$dati['foto']?>[/img]</font></td>
<td width="20%" align="center">
<font color="#FFFFFF" face="Tahoma" size="2"><?=$dati['nome']?></font></td>
<td width="20%" align="center">
<font color="#FFFFFF" face="Tahoma" size="2"><a href="prodotti.php?ricerca=<?=$idcategoria?>"><?=$ categoria?></font></td>
<td width="20%" align="center">
<font color="#FFFFFF" face="Tahoma" size="2">Modifica</font></td>
<td width="20%" align="center">
<font color="#FFFFFF" face="Tahoma" size="2"><input type="checkbox" name="cancella" value="<?=$idprodotto?>"></font></td>
</tr>
</form>
Nessun problema, visualizza tutto e mi costruisce anche l checkbox con lo stesso nome e valori diversi.
Mi da problemi nel conteggio dell checkbo selezionate nel javascript.
Il codice è questo:
<script>
function controllo_selezione(){
var checkbox_choices = 0;
for (counter = 0; counter < mioform.cancella.length; counter++)
{
if (mioform.cancella[counter].checked)
{ checkbox_choices = checkbox_choices + 1;
}
}
alert(checkbox_choices);
}
</script>
Nell'allert anche se seleziono le checkbox mi da sempre 0
Come mai?? Sto impazzendo!!!