Ver Mensaje Individual
  #92 (permalink)  
Antiguo 14/01/2003, 16:42
haven
 
Fecha de Ingreso: febrero-2002
Ubicación: Navarra
Mensajes: 701
Antigüedad: 22 años, 1 mes
Puntos: 2
92 - Impedir que seleccionen mas de dos checkbox

P: Impedir que seleccionen mas de dos checkbox en un formulario

R:

Código PHP:

<script>

function 
countChoices(obj) {
max 1// max. number allowed at a time

obj.form.PollVote1.checked// your checkboxes here
obj.form.PollVote2.checked;

// add more if necessary

count = (0) + (0);
// If you have more checkboxes on your form
// add more (box_ ? 1 : 0) 's separated by '+'

if (count max) {
alert("Atencion! Solo puede seleccionar " max " opcion! \Quite una de ellas si quiere seleccionar otra.");
obj.checked false;
}
}


</script>

Y el campo checkbox es de la forma

<form name="form">

<input type="checkbox" value="1" name="PollVote1" onClick="countChoices(this)">

<input type="checkbox" value="2" name="PollVote2" onClick="countChoices(this)">

<form>

Si tienes los campos de esta forma (gracias tunait):

<form name="form">

<input type="checkbox" value="1" name="PollVote" onClick="countChoices(this)">

<input type="checkbox" value="2" name="PollVote" onClick="countChoices(this)">

<form>


deberás poner:

a = obj.form.PollVote[1].checked; // your checkboxes here
b = obj.form.PollVote[2].checked; 
Un saludo

Última edición por haven; 15/01/2003 a las 04:00