Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/08/2015, 09:38
DanteNight
 
Fecha de Ingreso: julio-2015
Mensajes: 6
Antigüedad: 8 años, 10 meses
Puntos: 0
Dar Alerta Máximo Sumado con Checkbox

Necesito dar una alerta cuando el máximo que es 32 se alcanzado o pasado y no marque ese checkbox se que es algo simple recién inicio en javascripts.

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. var total = 0, maxi = 32;
  3.  
  4.  
  5. function sumar(valor) {
  6. total += valor;  
  7. document.unc.total.value=total;
  8.  
  9. }
  10.  
  11. function restar(valor) {
  12. total-= valor;  
  13. document.unc.total.value=total;
  14.  
  15. }
  16.  
  17.  
  18. </script>

eh colocado un if realizando la validacion al final pero solo suma y no resta luego

Código HTML:
Ver original
  1. <form method="post" action="imprimir.php" name="unc" id="unc";>

Código PHP:
Ver original
  1. if($estatus57 == 'A'){
  2.    
  3.             } else {
  4.                
  5. echo "<tr>";
  6. echo "<td>".$fila97['codmateria']."</td>";
  7. echo utf8_encode ("<td>".$fila97['nombremateria']."</td>");
  8. echo "<td>".$fila97['uc']."<input type='checkbox' name='uc' onClick='if (this.checked) sumar(15); else restar(15)' value='checkbox';\>"."</td>";
  9. echo "<td>".$fila97['semestre']."</td>";
  10. echo "</tr>";
  11. }
  12.  
  13.        
  14. if($estatus48 == 'A'){
  15.  
  16.            
  17.             } else {
  18. echo "<tr>";
  19. echo "<td>".$fila88['codmateria']."</td>";
  20. echo utf8_encode ("<td>".$fila88['nombremateria']."</td>");
  21. echo "<td>".$fila88['uc']."<input type='checkbox' name='uc' onClick='if (this.checked) sumar(15); else restar(15)' value='checkbox';\>"."</td>";
  22. echo "<td>".$fila88['semestre']."</td>";
  23. echo "</tr>";      
  24.        
  25.             }
  26.            
  27. if($estatus42 == 'A'){
  28.  
  29.            
  30.             } else {
  31. echo "<tr>";
  32. echo "<td>".$fila82['codmateria']."</td>";
  33. echo utf8_encode ("<td>".$fila82['nombremateria']."</td>");
  34. echo "<td>".$fila82['uc']."<input type='checkbox' name='uc' onClick='if (this.checked) sumar(3); else restar(3)' value='checkbox';\>"."</td>";
  35. echo "<td>".$fila82['semestre']."</td>";
  36. echo "</tr>";

Soy nuevo en programacion asi que el codigo esta algo feo tengo que aprender a minimizar se acepta cualquier opinion critica que me ayude a mejorar y solucionar este problema