Ik heb de volgende tabel
gemaakt die de gebruiker de mogelijkheid geeft om selectievakjes te gebruiken om de selectie aan te vinken. Ik beperkte het aantal selectie tot vier, maar het selecteerde meer dan 4 keuzes.
HTML:
<table width="100%" border="0">
<tr>
<th width="37%" height="19" align="center" bgcolor="#CCCCCC">
Biological
</th>
<th width="37%" align="center" bgcolor="#CCCCCC">
Psychological
</th>
<th width="37%" align="center" bgcolor="#CCCCCC">
Social
</th>
</tr>
<tr>
<td>
<input type="radio" name="Antidepressant" id="Antidepressant" value="Antidepressant" onclick="chkcontrol(1)" />
Antidepressant</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<input type="radio" name="Antipsychotic oral" id="Antipsychotic oral" value="Antipsychotic oral" onclick="chkcontrol(2)" />
Antipsychotic oral</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<input type="radio" name="Antipsychotic_depot" id="Antipsychotic depot" value="Antipsychotic depot" onclick="chkcontrol(3)" />
Antipsychotic depot</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<input type="radio" name="Bblocker" id="B-blocker" value="B-blocker" onclick="chkcontrol(4)" />
B-blocker</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<input type="radio" name="Benzodiazepine" id="Benzodiazepine" value="Benzodiazepine" onclick="chkcontrol(5)" />
Benzodiazepine</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<input type="radio" name="Mood_stabiliser" id="Mood stabiliser" value="Mood stabiliser" onclick="chkcontrol(6)" />
Mood stabiliser</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<input type="radio" name="ECT" id="ECT" value="ECT" onclick="chkcontrol(7)" />
ECT</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<input type="radio" name="Otherbio" id="Other" value="Other" />
Other</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
Het script werd gebruikt om het aantal selectie te checeren:
function chkcontrol(j) {
var total = 0;
for (var i = 0; i < document.form1.ckb.length; i++) {
if (document.form1.ckb[i].checked) {
total = total + 1;
}
if (total > 4) {
alert("Please Select only three")
document.form1.ckb[j].checked = false;
return false;
}
}
}
Hier is een screenshot:
