Ver Mensaje Individual
  #6 (permalink)  
Antiguo 29/11/2014, 16:20
Avatar de nexus44
nexus44
 
Fecha de Ingreso: octubre-2012
Ubicación: Piura
Mensajes: 108
Antigüedad: 11 años, 6 meses
Puntos: 1
Respuesta: Darle valor checkbox n00 seleccionado

En forma general he logrado seleccionar los primeros 2 checkbox y me arroja = 1 y el 3ero en 0 todo bien hasta hay me aparece en orden , pero cuando selecciono desde el segundo el orden cambia .
Código PHP:
Ver original
  1. <form action="#" method="post" >
  2. <?php
  3. $a=0;
  4. while($a<3){
  5. ?>
  6. <input type="checkbox" name="check_list[]" value="1" ><label><?php echo $a; ?></label>
  7. <input type="text" name="codigo[<?php echo $a; ?>]" value="<?php echo $a; ?>" />
  8. <br/>
  9. <br />
  10. <?php
  11. $a++;
  12. }
  13. ?>
  14. <input type="submit" name="submit" value="Submit"/>
  15. </form>
  16. <?php
  17. if(isset($_POST['submit'])){
  18.  
  19. $opciones=$_POST['check_list'];
  20. $codigo=$_POST['codigo'];
  21. $i=0;
  22. $n=count($codigo);
  23. while($i<$n)
  24. {      
  25. if (!isset($opciones[$i])){
  26. $opciones[$i]=0;
  27. }
  28. else{
  29. $opciones[$i]=1;
  30. }
  31.  echo $codigo[$i].'->'.$opciones[$i].'<br>';
  32.  $i++;
  33. }
  34. }
  35. ?>
__________________

"Nuestra capacidad se aleja de la Humanidad"