Bonjour,
je voudrais sur un formulaire rendre obligatoire la coche de case à cocher, mais aussi de pouvoir n'en cocher que 2 maximum.
j'ai réalisé un prog mais cela ne fonctionne pas càd il ne teste pas mes cases à cochés
voici mon prog:
mon quest:Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 <script language="JavaScript"> <!--- function OnChange() { } function OnValidate() { var sphinx = document.sphinx; if (sphinx.nextpage && sphinx.nextpage.value == '-1') return true; var i,n,r; if (sphinx.v1.value.indexOf('|', 0) != -1) { Alert('div1', "Le caractère '|' est illégal."); return false; } } if (IsVisible('div3')) { i = 0; while (i < sphinx.v2.length && sphinx.v2[i].checked != '1') i++; if (i == sphinx.v2.length) { Alert('div3', "Saisie obligatoire."); return false; } } if (IsVisible('div3')) { i = 0; n = 0; while (i < sphinx.v2.length && n <= 2) { if (sphinx.v2[i].checked == '1') n++; i++; } if (n > 2) { Alert('div3', "Il y a trop de modalités cochées."); return false; } } return true; } //--> </script>
Merci pour votre aide.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 <form method="post" name="sphinx" action="toto.htm" onSubmit="return OnValidate()"> <input type="checkbox" name="v2" value="1" id="v2" onClick="OnChange()"/> <label for="v2"> Dreamweaver</label> </td> <td width="33%"><input type="checkbox" name="v2" value="3" id="v22" onClick="OnChange()"/> <label for="v22"> Nvu</label> </td> <td width="33%"> </td> </tr> <tr style="font: 10pt Arial; color: #000000"> <td width="33%"><input type="checkbox" name="v2" value="2" id="v23" onClick="OnChange()"/> <label for="v23"> Edit plus</label> </td> <td width="33%"><input type="checkbox" name="v2" value="4" id="v24" onClick="OnChange()"/> <label for="v24"> Frontpage</label> </form>
A+