puo andare bene un esempio cosi?
ho cercato di farlo in modo semplice con delle funzioni che si possono riusare.
Codice PHP:
<html>
<head>
<title>aste</title>
<SCRIPT LANGUAGE="JavaScript">
var indicefocus=0;
function isChecked(elemento,indice)
{
var mycheck=false;
for (i = 0; i < elemento.length; i++)
{
if(elemento[i].checked)
{
mycheck=true;
}
}
if(!mycheck)
{
indicefocus=indice;
alert("Non hai compilato la domanda numero "+indicefocus);
}
return mycheck;
}
function controllocampi()
{
errore=false;
for (indice = 1; indice <=2; indice++)
{
if(!isChecked(document.test.elements["domanda"+indice],indice))
{
errore=true;
break;
}
}
if(errore)
{
document.test.elements["domanda"+indicefocus][0].focus();
}
else
{
alert("ho inviato tutto");
}
}
</script>
</head>
<body>
<form name="test" id="test" action="javascript:controllocampi();">
DOMANDA 1
<input id="domanda1" name="domanda1" type="checkbox" value="1" />A
<input id="domanda1" name="domanda1" type="checkbox" value="2" />B
<input id="domanda1" name="domanda1" type="checkbox" value="3" />C
<input id="domanda1" name="domanda1" type="checkbox" value="4" />D
DOMANDA 2
<input id="domanda2" name="domanda2" type="checkbox" value="1" />A
<input id="domanda2" name="domanda2" type="checkbox" value="2" />B
<input id="domanda2" name="domanda2" type="checkbox" value="3" />C
<input id="domanda2" name="domanda2" type="checkbox" value="4" />D
<input type="submit" value="INVIA" />
</form>
</body>
</html>