Prova questo (avevi già tutto quel che occereva nel tuo script)
codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
var checkflag = "true";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
f(document.getElementById('form1'));
return "Deseleziona Tutti"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;}
checkflag = "false";
f(document.getElementById('form1'));
return "Seleziona Tutti"; }
}
function f(frmObj)
{
var strVal = "";
var el = frmObj.elements;
var nFields = el.length;
var sepStr = "-";
for ( n = 0 ; n < nFields ; n++ )
{
if (el[n].type == "checkbox" && el[n].checked)
{
if (strVal.length > 0) strVal += sepStr;
strVal += el[n].value;
}
}
document.form1.who.value = strVal;
}
</script>
<form id="form1" name="form1" method="post" action="test.php">
<input type=button value="Deseleziona Tutti" onClick="this.value=check(this.form.list)">
<input type=checkbox name=list value="1" checked onClick="f(this.form);">Opzione 1
<input type=checkbox name=list value="2" checked onClick="f(this.form);">Opzione 2
<input type=checkbox name=list value="3" checked onClick="f(this.form);">Opzione 3
<input type=checkbox name=list value="4" checked onClick="f(this.form);">Opzione 4
<input type=checkbox name=list value="5" checked onClick="f(this.form);">Opzione 5
<input type=text name=who>
<input type="submit" name="Submit" value="Invia">
</form>
<script language="JavaScript" type="text/javascript">
<!--
f(document.getElementById('form1'));
//-->
</script>
</body>
</html>