Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/11/2008, 09:59
Avatar de ZiTAL
ZiTAL
 
Fecha de Ingreso: marzo-2004
Ubicación: Bermio (Bizkaia)
Mensajes: 1.545
Antigüedad: 20 años, 2 meses
Puntos: 62
Respuesta: Validacion de checkbox

Código HTML:
<html>
<head>
<script type="text/javascript" src="validate.js"> 
</script>
</head>
<body>
<form action="accionCarrito" onsubmit="return validate(this)">
<input type="checkbox" name="seleccion[]" value="<!--<?php echo $v['id']; ?> -->">
<input type="checkbox" name="seleccion[]" value="<!--<?php echo $v['id']; ?> -->">
<input type="checkbox" name="seleccion[]" value="<!--<?php echo $v['id']; ?> -->">
<input type="reset" value="Borrar" onclick="window.bot=this"></td>
<input type="submit" value="Actualizar" onclick="window.bot=this">
</form>
</body>
</html> 
validate.js
Código PHP:
function validate(esto)
{
    var 
error '';
    var 
validate false;
    var 
input esto.getElementsByTagName('input');
    for(var 
i=0;i<input.length;i++)
    {
        switch(
input[i].type)
        {
            case 
'checkbox':
                if(
input[i].checked==true)
                {
                    
validate true;
                }
                break;
            default:
                break;
        }
    }
    if(
validate==true)
    {
        return 
true;
    }
    else
    {
        
alert('Por favor debe seleccionar al menos un producto');
        return 
false;
    }

__________________
http://zital.no-ip.org
____________________

Euskerie ahuen eta bijotzan