Ver Mensaje Individual
  #3 (permalink)  
Antiguo 30/04/2012, 11:34
Avatar de diamari
diamari
 
Fecha de Ingreso: marzo-2012
Mensajes: 95
Antigüedad: 12 años, 1 mes
Puntos: 30
Respuesta: Validar un checkbox

Ahora debería funcionar:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WKF - Formulaire commande catalogue formation</title>

<script type="text/javascript">

function MM_validateForm() { //v4.0

if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if(val != null && test=='Rchecked'){ var z = ''; var marcado = false;
while(document.getElementById(nm + z)){ var elemento = document.getElementById(nm + z);
if(elemento.checked) marcado = true; if(z == ''){ z = 1;}else{ z++;}}
if(marcado==false){ val.value = '';}}

if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+=' Vous devez bien ecrire une direction e-mail.\n';
} else if (test!='B') { num = parseFloat(val);

if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R')errors += '\n';}
} if (errors) alert('Vous devez remplir les champs obligatoires\n'+errors);
document.MM_returnValue = (errors == '');

} }
</script>




</head>

<body>
<div id="top_form" style=" width:800px; height:auto; margin: 0px auto auto; margin-bottom:20px; border-bottom: solid 3px #F00; background-color:#FFF ">
<div style="width:800px; border-bottom: solid #F00; background-color:#FFF; margin-top: 12px;">
<img src="http://www.forosdelweb.com/f13/images/autre/logoLSform.jpg" />

</div>

<div class="Estilo2" style="text-align:left; font-family: Arial, Helvetica, sans-serif ; color:black; font-size:0.7em; padding-left: 80px;">

<form id="form1" name="form1" method="post" action="sendLS.php" onsubmit="return performCheck('form1', rules, 'inline');return false;">
<h3 style="color:#F00; margin: 20px -57px;">Pour télécharger le catalogue 2012, merci de renseigner le formulaire ci-dessous :</h3>
<p>

<label>
<input type="radio" name="civilite" value="madame" id="civ_0" />
Madame</label>

<label>
<input type="radio" name="civilite" value="madmoiselle" id="civ_0" />
Mademoiselle</label>

<label>
<input type="radio" name="civilite" value="monsieur" id="civ_0" />
Monsieur</label>
</p>

<p>
Prénom<cite style="color:red">*</cite><br />
<input name="prenom" type="text" id="prenom" style="width:200px" />
</span><br />
Nom<cite style="color:red">*</cite><br />
<label>
<input name="nombrele" type="text" id="nombre" style="width:200px" />
</label>
<br />

Email<cite style="color:red">*</cite><br />
<input name="email" type="text" id="email" style="width:200px" />
<br />
Fonction<cite style="color:red">*</cite><br />
<input name="fonction" type="text" id="fonction" style="width:200px" /><br />
Raison sociale<cite style="color:red">*</cite><br />
<input name="rsociale" type="text" id="rsociale" style="width:200px" />
</p>
<p style="color:red; font-size:0.9em; margin-top:-5px">Les champs en rouge sont obligatoires</p>

<h3 style="color:#F00; margin: 20px -57px;">Centre(s) d´intérêt<cite style="color:red">*</cite></h3>

<p>
<label>
<input name="interet" type="checkbox" id="interet" value=" 1 " />
Pratique du droit social</label>
<br />
<label>
<input type="checkbox" name="interet0" value=" 2 " id="interet1" />
Relations sociales</label>
<br />
<label>
<input type="checkbox" name="interet1" value=" 3 " id="interet2" />
Stratégie et pilotage des RH</label>
<br />
<label>
<input type="checkbox" name="interet2" value="4 " id="interet3" />
Formation et développement des RH</label>
<br />
<label>
<input type="checkbox" name="interet3" value="5 " id="interet4" />
Santé au travail</label>
<br />
<label>
<input type="checkbox" name="interet4" value="6 " id="interet5" />
Paye, rémunérations et protection sociale</label>
<br />
<label>
<input type="checkbox" name="interet5" value="Représentants Personnel " id="interet6" />
Représentants du personnel</label>
<br />

</p>
<p>
<label>
<input style="margin-bottom:40px; margin-top:40px" name="Submit" type="submit" onclick="MM_validateForm('interet','','Rchecked',' prenom','','R','nombre','','R','email','','RisEmai l','sisi','' );return document.MM_returnValue" value="Envoyer" />
</label>
</p>

</form>

</div>
</div>
</body>
</html>

solo tienes que añadir el id de los check y Rchecked, los checkbox necesitan es enumerados de la siguiente forma:

check
check1
check2
check3
etc...