salut,
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:
<script language="JavaScript">
<!---
function OnChange(){
}
function OnValidate(){
var sphinx = document.sphinx;
if(sphinx.nextpage && sphinx.nextpage.value == '-1')
returntrue;
var i,n,r;
if(sphinx.v1.value.indexOf('|', 0) != -1){
Alert('div1', "Le caractère '|' est illégal.");
returnfalse;
}
}
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.");
returnfalse;
}
}
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.");
returnfalse;
}
}
returntrue;
}
//-->
</script>
mon quest:
<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>
Merci pour l'aide.