Snippet Name: Compti checkboxes
Descripció: Asseguri's que els usuaris només puguin seleccionar nombre X de checkboxes.
Comentari: (cap)
Llengua: JAVASCRIPT
Subratlli Mode: JAVASCRIPT
Finalment Modificava: 27 de febrer, de 2009
|
<!DOCTYPE html PÚBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> content="text/html "<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Escriu"; charset=iso-8859-1" /compte de check(){ de FUNCIÓ de > <script> = 0;
str = '';
FOR(x=0; x<document.form1.elements["checkbox[]"].length; x++){ str de IF(document.form1.elements["checkbox[]"][x].checked==TRUE){ += document.form1.elements["checkbox[]"][x].value + ', ';
count++;
} } IF(count==0){ ALERT("You ha d'escollir com a mínim 1");
RETORN FALS;
} MÉS IF(count>3){ ALERT("You pot escollir un màxim de 3");
RETORN FALS;
} MÉS { ALERT("You escollia " + compte + ": " + str.substring(0,str.length-1));
document.form1.submit();
} } </script> </head> <body> <form NAME="form1" id="form1" method="post" action=" onsubmit="return check()"> <p> <input type="checkbox NAME="checkbox["] value="red" /> Red<br /> <input type="checkbox NAME="checkbox["] " value="green" /> Green<br /> <input type="checkbox NAME="checkbox["] " value="blue" /> Blue<br /> <input type="checkbox NAME="checkbox["] " value="black" /> Black<br /> <input type="checkbox NAME="checkbox["] " value="white" /> White<br /> <input type="checkbox NAME="checkbox["] " value="yellow" /> Yellow<br /> <input type="checkbox NAME="checkbox["] " value="purple" /Porpra de > </p> <p> <input type="submit" NAME="Submit value="Click" Jo" /> </p> </form> </body> </html> |