Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/06/2010, 19:24
WinderJerter
 
Fecha de Ingreso: agosto-2009
Mensajes: 292
Antigüedad: 14 años, 8 meses
Puntos: 5
problemas con window.onload

Hola que tal, hora acabo de implementar otro script en una pagina que tengo y funcionaba bien pero a la hora de poner el otro script que tiene un windows.onload dejo de funcionar la function countCheckboxes

Alguien sabe como solucionar esto

Código HTML:
Ver original
  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  2. <title>Untitled Document</title>
  3.  
  4.     <script type="text/javascript">
  5.     function countCheckboxes()
  6.     {
  7.             var form = document.getElementById('album');
  8.             var count = 0;
  9.             for(var n = 0; n < form.length; n++)
  10.             {
  11.                if(form[n].name == 'addAlbum[]' && form[n].checked)
  12.                {
  13.                    count++;
  14.                }
  15.             }
  16.             document.getElementById('checkCount').innerHTML = count;
  17.     }
  18.        </script>
  19.  
  20. <script type="text/javascript">
  21. //This Function Creates your Cookie for you just pass in the Cookie Name, Value, and number of days before you want it to expire.
  22. function CreateCookie(name,value,days)
  23. {
  24.     if (days)
  25.     {
  26.         var date = new Date();
  27.         date.setTime();
  28.         var expires = "; expires="+date.toGMTString();
  29.     }
  30.     else var expires = "";
  31.     document.cookie = name + "=" + value + expires + "; path=/";
  32. }
  33.  
  34. //This Function reads the value of a given cookie for you.  Just pass in the cookie name and it will return the value.
  35. function ReadCookie(name)
  36. {
  37.     var nameEQ = name + "=";
  38.     var ca = document.cookie.split(';');
  39.     for(var i=0;i < ca.length;i++) {
  40.         var c = ca[i];
  41.         while (c.charAt(0)==' ') c = c.substring(1,c.length);
  42.         if (c.indexOf(nameEQ) == 0)
  43.        {
  44.            return c.substring(nameEQ.length,c.length);
  45.        }
  46.     }
  47.     return null;
  48. }
  49.  
  50. //This Function Erases Cookies.  Just pass in the name of the cookies you want erased.
  51. function EraseCookie(name)
  52. {
  53.     CreateCookie(name,"",-1);
  54. }
  55.  
  56. //Sets or UnSets Cookies for given checkbox after it's been clicked on/off.
  57. function ChangeBox(CheckBox)
  58. {
  59.     if (document.getElementById(CheckBox).checked)
  60.     {
  61.         var CurrentCookie = ReadCookie("checkimg");
  62.         CurrentCookie = CurrentCookie + CheckBox;  
  63.         CreateCookie("checkimg",CurrentCookie,"100");
  64.     }
  65.     else
  66.     {
  67.         var CurrentCookie = ReadCookie("checkimg");
  68.         CurrentCookie = CurrentCookie.replace(CheckBox,"");
  69.         CreateCookie("checkimg",CurrentCookie,"100");
  70.     }
  71. }
  72. //Runs on body load to check history of checkboxes on the page.
  73. function CheckCookies()
  74. {
  75.     var CurrentCookie = ReadCookie("checkimg");
  76.     for (i=0; i<document.CheckList.elements.length; i++)
  77.     {
  78.         if (document.CheckList.elements[i].type == "checkbox")
  79.         {
  80.             document.CheckList.elements[i].onclick = function() {ChangeBox(this.id);};
  81.            if (CurrentCookie && CurrentCookie.indexOf(document.CheckList.elements[i].id) > -1)
  82.             {
  83.                 document.CheckList.elements[i].checked = true;
  84.             }
  85.         }
  86.     }
  87. }
  88.  
  89. //Clears Form
  90. function ClearBoxes()
  91. {
  92.     for (i=0; i<document.CheckList.elements.length; i++)
  93.     {
  94.         if (document.CheckList.elements[i].type == "checkbox")
  95.         {
  96.             document.CheckList.elements[i].checked = false;
  97.             ChangeBox(document.CheckList.elements[i].id);
  98.         }
  99.     }
  100. }
  101. window.onload = CheckCookies;
  102.  
  103. </head>

Saludos y gracias de antemano