Originariamente inviato da Certe Notti
2) so che per questa funzione ci sarebbero i radio button, ma è possibile fare in modo che la selezione di un checkbox pori alla deselezione degli altri in maniera che sempre e soltanto uno sia quello che si seleziona?
codice:
<html>
<head>
<script type="text/javascript" language="JavaScript">
<!--
function makeSingleSelection( __hForm, __hElement )
{
for (var i=0; i<__hForm.length; i++)
if (__hForm.elements[i].type == "checkbox" )
__hForm.elements[i].checked = false;
__hElement.checked = true;
}
//-->
</script>
</head>
<body>
<form>
<input type="checkbox" onclick="makeSingleSelection( this.form, this );" /> Checkbox #1
<input type="checkbox" onclick="makeSingleSelection( this.form, this );" /> Checkbox #2
<input type="checkbox" onclick="makeSingleSelection( this.form, this );" /> Checkbox #3
<input type="checkbox" onclick="makeSingleSelection( this.form, this );" /> Checkbox #4
<input type="checkbox" onclick="makeSingleSelection( this.form, this );" /> Checkbox #5
<input type="checkbox" onclick="makeSingleSelection( this.form, this );" /> Checkbox #6
<input type="checkbox" onclick="makeSingleSelection( this.form, this );" /> Checkbox #7
<input type="checkbox" onclick="makeSingleSelection( this.form, this );" /> Checkbox #8
<input type="checkbox" onclick="makeSingleSelection( this.form, this );" /> Checkbox #9
</form>
</body>
</html>