Yadgar: Zugriff auf Checkboxen in einer Tabelle

Beitrag lesen

High!

Im Rahmen der Programmierung eines Lotto-Simulators (mit Auswertung durch ein PHP-Skript) will ich beim Abschicken des Lottoschein-Formulars mittels Javascript prüfen, ob tatsächlich genau 6 Zahlenfelder angekreuzt wurden.

Dazu würde ich gerne den checked-Status der 49 einzelnen Checkboxen im Formular auslesen... leider funktioniert der Zugriff auf diese Checkboxen nicht so, wie ich mir das naiverweise(?) vorgestellt hatte:

<form name="Lottoschein" action="Ziehung.php" method="post">
<table width="250">
<tr>
<td>1<br><input type="checkbox" name="1"></input></td>
<td>2<br><input type="checkbox" name="2"></input></td>
<td>3<br><input type="checkbox" name="3"></input></td>
<td>4<br><input type="checkbox" name="4"></input></td>
<td>5<br><input type="checkbox" name="5"></input></td>
<td>6<br><input type="checkbox" name="6"></input></td>
<td>7<br><input type="checkbox" name="7"></input></td>
</tr>
<tr>
<td>8<br><input type="checkbox" name="8"></input></td>
<td>9<br><input type="checkbox" name="9"></input></td>
<td>10<br><input type="checkbox" name="10"></input></td>
<td>11<br><input type="checkbox" name="11"></input></td>
<td>12<br><input type="checkbox" name="12"></input></td>
<td>13<br><input type="checkbox" name="13"></input></td>
<td>14<br><input type="checkbox" name="14"></input></td>
</tr>
<tr>
<td>15<br><input type="checkbox" name="15"></input></td>
<td>16<br><input type="checkbox" name="16"></input></td>
<td>17<br><input type="checkbox" name="17"></input></td>
<td>18<br><input type="checkbox" name="18"></input></td>
<td>19<br><input type="checkbox" name="19"></input></td>
<td>20<br><input type="checkbox" name="20"></input></td>
<td>21<br><input type="checkbox" name="21"></input></td>
</tr>
<tr>
<td>22<br><input type="checkbox" name="22"></input></td>
<td>23<br><input type="checkbox" name="23"></input></td>
<td>24<br><input type="checkbox" name="24"></input></td>
<td>25<br><input type="checkbox" name="25"></input></td>
<td>26<br><input type="checkbox" name="26"></input></td>
<td>27<br><input type="checkbox" name="27"></input></td>
<td>28<br><input type="checkbox" name="28"></input></td>
</tr>
<tr>
<td>29<br><input type="checkbox" name="29"></input></td>
<td>30<br><input type="checkbox" name="30"></input></td>
<td>31<br><input type="checkbox" name="31"></input></td>
<td>32<br><input type="checkbox" name="32"></input></td>
<td>33<br><input type="checkbox" name="33"></input></td>
<td>34<br><input type="checkbox" name="34"></input></td>
<td>35<br><input type="checkbox" name="35"></input></td>
</tr>
<tr>
<td>36<br><input type="checkbox" name="36"></input></td>
<td>37<br><input type="checkbox" name="37"></input></td>
<td>38<br><input type="checkbox" name="38"></input></td>
<td>39<br><input type="checkbox" name="39"></input></td>
<td>40<br><input type="checkbox" name="40"></input></td>
<td>41<br><input type="checkbox" name="41"></input></td>
<td>42<br><input type="checkbox" name="42"></input></td>
</tr>
<tr>
<td>43<br><input type="checkbox" name="43"></input></td>
<td>44<br><input type="checkbox" name="44"></input></td>
<td>45<br><input type="checkbox" name="45"></input></td>
<td>46<br><input type="checkbox" name="46"></input></td>
<td>47<br><input type="checkbox" name="47"></input></td>
<td>48<br><input type="checkbox" name="48"></input></td>
<td>49<br><input type="checkbox" name="49"></input></td>
</tr>
</table>
<input type="submit" value="Ziehen!"></input>
</form>

Die Javascript-Anweisungen

chk = document.getElementsByName("1").checked;
  alert(chk);

führen zwar nicht zu einer Meldung auf der Fehlerkonsole, aber zur Ausgabe von "undefined". Wieso? Eigentlich sollte "checked" doch vom Typ "bool" sein und folglich "true" oder "false" angezeigt werden...

Bis bald im Khyberspace!

Yadgar