Ver Mensaje Individual
  #12 (permalink)  
Antiguo 28/05/2012, 06:53
Avatar de Nemutagk
Nemutagk
Colaborador
 
Fecha de Ingreso: marzo-2004
Ubicación: México
Mensajes: 2.633
Antigüedad: 20 años, 1 mes
Puntos: 406
Respuesta: Multiple checbox-paso de parametro como string

no, no lo había provado, de hecho, lo hice al "vuelo", tenia un 2 errores, pero ya que cheque el código mas a "fondo", decidi "mejorarlo" un poco, ya que no estaba seguro si el form tomaría el valor de icondenv cuando ya se ah llamado al evento onsubmit...

Código Javascript:
Ver original
  1. function getValues() {
  2.                  var allvalues = '';
  3.                  for(var i=0; i<document.miForm.elements.length; i++) {
  4.                       if (document.miForm.elements[i].type == "checkbox") {
  5.                            if (document.miForm.elements[i].checked) {
  6.                                 allvalues = allvalues + ' ' + document.miForm.elements[i].value;
  7.                            }
  8.                       }
  9.                  }
  10.              
  11.                  if(allvalues != '') {
  12.                       var oculto = document.getElementById('Idcondenv');
  13.                       oculto.value = allvalues;
  14.                 }
  15.             }
  16.  
  17.             function checkValues() {
  18.                 if (document.getElementById('Idcondenv').value == '') {
  19.                     alert('Debes seleccionar al menos 1 checkbox');
  20.                     return false;
  21.                 }
  22.             }

Código HTML:
Ver original
  1. <form name="miForm" method="get" action="checkbox.php" onsubmit="return checkValues();">
  2.              <input type="checkbox" value="1" />
  3.              <input type="checkbox" value="2" />
  4.              <input type="checkbox" value="3" />
  5.              <input type="checkbox" value="4" />
  6.              <input type="checkbox" value="5" />
  7.              <input type="checkbox" value="6" />
  8.              <input type="hidden" id="Idcondenv" name="Idcondenv" />
  9.              <input type="submit" value="Enviar" onclick="getValues()" />
  10.         </form>
__________________
Listo?, tendría que tener 60 puntos menos de IQ para considerarme listo!!!
-- Sheldon Cooper
http://twitter.com/nemutagk
PD: No contestaré temas vía mensaje personal =)