site de Fabien Torre


Source de formjsradiocheckbox1.html

1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2: <HTML> 3: <HEAD> 4: <TITLE>Des questions radio et checkbox</TITLE> 5: <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> 6: <link REL="stylesheet" TYPE="text/css" HREF="https://fabien-torre.fr/include/css/ft-v1.css"> 7: <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> 8: 9: 10: function checkCheckBox (name,intitule,min,max) { 11: 12: let boutons = document.F.elements[name]; 13: let nb = boutons.length; 14: let choisi = 0; 15: let i = 0; 16: 17: while (i < nb) { 18: 19: if (boutons[i].checked) { 20: choisi = choisi + 1; 21: if (choisi > max) { 22: alert("Trop de réponses pour la question "+intitule+"\n"); 23: return false; 24: } 25: } 26: 27: i = i + 1; 28: } 29: 30: if (choisi < min) { 31: alert("Manque de réponse pour la question "+intitule+"\n"); 32: return false; 33: } 34: 35: 36: return true; 37: 38: } 39: 40: 41: function checkRadio (name,intitule) { 42: 43: let boutons = document.F.elements[name]; 44: let nb = boutons.length; 45: let i = 0; 46: 47: while (i < nb) { 48: if (boutons[i].checked) { 49: return true; 50: } 51: i = i + 1; 52: } 53: 54: alert("Veuillez répondre à la question "+intitule+" !"); 55: 56: return false; 57: 58: } 59: 60: 61: function check () { 62: 63: return checkRadio("glace","glace préférée") 64: && checkCheckBox ("film[]","film préféré",2,3) 65: && checkRadio("ville","ville préférée"); 66: 67: } 68: 69: 70: </script> 71: </HEAD> 72: <BODY> 73: 74: <DIV CLASS="menu"> 75: <DIV CLASS="partmenu"> 76: <UL> 77: <LI> voir le <A HREF="https://fabien-torre.fr/Enseignement/tp/JavaScript/formjsradiocheckbox1.html.src">code de cette page</A> 78: <LI> retour à la page des 79: <A HREF="https://fabien-torre.fr/Enseignement/tp/JavaScript/">Travaux pratiques JavaScript</A> 80: <LI> retour à la page de <A HREF="https://fabien-torre.fr/">Fabien Torre</A> 81: </UL> 82: </DIV> 83: </DIV> 84: <DIV CLASS="page"> 85: 86: <H1>Des questions radio et checkbox</H1> 87: 88: 89: <div class="presentation"> 90: Que des questions obligatoires et deux ou trois réponses pour 91: la question à choix multiples, ni plus, ni moins. 92: </div> 93: 94: 95: 96: <FORM NAME="F" onSubmit="return check()" ACTION="gagne.php" METHOD="post"> 97: 98: Quelle est votre glace préférée ?<br> 99: <input type="radio" name="glace" value="choc"> Chocolat<br> 100: <input type="radio" name="glace" value="frai"> Fraise<br> 101: <input type="radio" name="glace" value="psit"> Pistache<br> 102: <input type="radio" name="glace" value="vani"> Vanille<br> 103: <br> 104: 105: 106: Quelle sont vos 2 ou 3 films préférés ?<br> 107: <input type="checkbox" name="film[]" value="mr"> Mystic River<br> 108: <input type="checkbox" name="film[]" value="rocky"> Rocky<br> 109: <input type="checkbox" name="film[]" value="et"> E.T. l'extraterrestre<br> 110: <input type="checkbox" name="film[]" value="tl"> Thelma et Louise <br> 111: <br> 112: 113: Quelle est votre ville préférée ?<br> 114: <input type="radio" name="ville" value="lille"> Lille<br> 115: <input type="radio" name="ville" value="paris"> Paris<br> 116: <input type="radio" name="ville" value="nantes"> Nantes<br> 117: <input type="radio" name="ville" value="marseille"> Marseille<br> 118: <br> 119: 120: 121: 122: <INPUT TYPE="submit"> 123: </FORM> 124: 125: <br> 126: <hr> 127: <div class="pied"> 128: &copy; <script type="text/javascript"> 129: <!-- 130: eval(unescape( 131: '%76%61%72%20%65%3d%27%66%61%62%69%65%6e%2e%74%6f%72%72'+ 132: '%65%27%2b%27%40%27%2b%27%75%6e%69%76%2d%6c%69%6c%6c%65'+ 133: '%33%2e%66%72%27%3b%76%61%72%20%74%3d%27%46%61%62%69%65'+ 134: '%6e%20%54%6f%72%72%65%27%3b%64%6f%63%75%6d%65%6e%74%2e'+ 135: '%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61'+ 136: '%69%6c%74%6f%3a%27%2b%65%2b%27%22%3e%27%2b%74%2b%27%3c'+ 137: '%2f%61%3e%27%29')); //--> 138: </script> 139: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 140: <a href="http://validator.w3.org/check/referer"><img src="https://fabien-torre.fr/Images/valid-xhtml10.png" alt="Valid XHTML 1.0!" height="31" width="88" /></a> 141: <a href="http://jigsaw.w3.org/css-validator/validator?uri=https://fabien-torre.fr/include/css/ft-v1.css"><img style="width:88px;height:31px" src="https://fabien-torre.fr/Images/vcss.png" alt="Valid CSS!" /></a> 142: </div> 143: </div> 144: 145: </BODY> 146: </HTML>
Fabien Torre Valid HTML5! Valid CSS!
site de Fabien Torre, université de Lille