Foros del Web » Programando para Internet » Javascript »

Problemas con checkbox

Estas en el tema de Problemas con checkbox en el foro de Javascript en Foros del Web. Este codigo me funciona sin problemas con Ie pero con mozilla no funciona...... cual es el problema ya he visto todo el foro pero aun ...
  #1 (permalink)  
Antiguo 03/11/2005, 08:55
 
Fecha de Ingreso: octubre-2005
Mensajes: 28
Antigüedad: 18 años, 6 meses
Puntos: 0
Exclamación Problemas con checkbox

Este codigo me funciona sin problemas con Ie pero con mozilla no funciona...... cual es el problema ya he visto todo el foro pero aun no encuentro la solucion....

Tengo varios Checkbox con el mismo nombre, pero el value es distinto para poder diferenciarlos...

<input type="checkbox" id="selectionCheck" value="id">
</input>

entonces cuando hago submit llama a GetSelectedItemsCount() y me entrega el numero checkbox que estan selecionados... si no hay ninguno me arroja 0.

Pero esto no me funciona con mozilla.

Código PHP:

function GetSelectedItemsCount()
{
    if (
typeof(document.Form.selectionCheck) != "undefined")
        return 
Sel_GetSelectedItemsCount(document.Form.selectionCheck);
    else
        return 
0;
}



function 
Sel_GetSelectedItemsCount(itemlist)
{
    if (
typeof(itemlist) == "undefined")
    {
        return 
0;
    }

    
cant itemlist.length;
    if(!
cant)
    {
        if (
itemlist.checked)
            return 
1;
    }
    else
    {
        
count 0;
        for(
gsici 0gsici cantgsici++)
        {
            if (
itemlist[gsici].checked)
                
count++;
        }
        
        return 
count;
    }    

  #2 (permalink)  
Antiguo 03/11/2005, 10:46
Avatar de KarlanKas
Moderador extraterrestre
 
Fecha de Ingreso: diciembre-2001
Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 22 años, 4 meses
Puntos: 61
Así me funciona con Nocilla 1.8a6:

Código PHP:
<html>
<
head>
    <
title>Untitled</title>
    <
script>
    function 
GetSelectedItemsCount()
{
    if (
typeof(document.forms['Form'].selectionCheck) != "undefined")
        return 
Sel_GetSelectedItemsCount(document.forms['Form'].selectionCheck);
    else
        return 
0;
}



function 
Sel_GetSelectedItemsCount(itemlist)
{
    if (
typeof(itemlist) == "undefined")
    {
        return 
0;
    }

    
cant itemlist.length;
    if(!
cant)
    {
        if (
itemlist.checked)
            return 
1;
    }
    else
    {
        
count 0;
        for(
gsici 0gsici cantgsici++)
        {
            if (
itemlist[gsici].checked)
                
count++;
        }
        
        return 
count;
    }    

    
</script>
</head>

<body><form name="Form" action="javascript:alert(GetSelectedItemsCount())" onsubmit="return GetSelectedItemsCount()">
<input type="checkbox" id="selectionCheck" value="id">
</input>
<input type="checkbox" id="selectionCheck" value="1">
</input>
<input type="checkbox" id="selectionCheck" value="2">
</input>
<input type="checkbox" id="selectionCheck" value="3">
</input>
<input type="checkbox" id="selectionCheck" value="4">
</input>
<input type="checkbox" id="selectionCheck" value="5">
</input>
<input type="submit">
</form>
</body>
</html> 
Un saludo!
__________________
Cómo escribir

No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia.
  #3 (permalink)  
Antiguo 03/11/2005, 13:41
 
Fecha de Ingreso: octubre-2005
Mensajes: 28
Antigüedad: 18 años, 6 meses
Puntos: 0
Gracias me sirvio....
  #4 (permalink)  
Antiguo 04/11/2005, 02:45
Avatar de KarlanKas
Moderador extraterrestre
 
Fecha de Ingreso: diciembre-2001
Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 22 años, 4 meses
Puntos: 61
Me alegro de que te sirviera!
__________________
Cómo escribir

No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:48.