Ver Mensaje Individual
Antiguo 14-ene-2003, 15:42   #92 (permalink)
haven
haven está en el buen camino
 
Fecha de Ingreso: noviembre-2002
Ubicación: Navarra
Mensajes: 664
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-ene-2003 a las 03:00.
haven está desconectado   Responder Citando