Witam
Próbuje napisać kod który zaznaczy mi wszystkie checkboxy o id="id" i name="id". Checkboxy wypluwane są w pętli w zależności od ilości użytkowników w bazie.
Użyłem poniżeszej funkcji ale nie działa, bawię się z tym już od ponad godziny i szukałem w necie info ale jakoś nie moge się z tym dogadać.
Proszę o pomoc w znalezieniu błędu.
```javascript
<!-- tutaj funkcja uzywana -->
<script>
(function(d)
{
"use strict";
var form=d.getElementsByTagName('form')[0]
,button=d.getElementsByTagName('button')[0];
button.addEventListener('click',function()
{
for(var i=0;i<form['check[]'].length;i++)
{
var t=form['check[]'][i];
if(i===0)
this.innerHTML=t.checked?'Zaznacz wszystkie':'Odznacz wszystkie';
t.checked=!t.checked;
}
},false);
}(document))
</script>
<div class="container text-center">
<h2>Przydzielanie dostępu studentom</h2>
<div class="alert alert-danger">Lista studentów bez dostępu do systemu!</div>
<a href="index.php"><button type="button" class="btn btn-default text-center">Powrót</button></a>
<br>
<form class="form" id="form" role="form" method="post" name="form" action="includes/do_student_add_access_for_all_checked.php">
<div class="form-group">
<table class="table table-striped">
<tr>
<td><button type="button">Zaznacz wszystkie</button></td>
<td>E-mail</td>
<td>Nazwa wyświetlana</td>
<td>Data rejestracji</td>
<td>
<SELECT name="id_gr" class="form-control">
<?php
while($gr=mysql_fetch_assoc($g))
{
echo('<option value="'.$gr['id_group'].'">'.$gr['name'].'</option>');
}
?>
</SELECT>
</td>
</tr>
<?php while($s=mysql_fetch_assoc($stud))
{
$tab[$i]=$s['id'];
// w tym miejscu są wypluwane checkboxy
echo('<tr><td><input name="id" id="id" type="checkbox" value="'.$tab[$i].'"></td><td>'.$s['user_email'].'</td><td>'.$s['user_nickname'].'</td><td>'.$s['user_register'].'</td><td></td></tr>');
print_r($tab[$i]);
$i++;
}
?>
</table>