Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/06/2010, 20:28
WinderJerter
 
Fecha de Ingreso: agosto-2009
Mensajes: 292
Antigüedad: 15 años, 5 meses
Puntos: 5
Respuesta: problemas con window.onload

Hola que tal zerokilled, el countCheckboxes no lo puse anteriormente, pero lo invoco asi <div id="checkCount">0</div>, aqui esta el codigo completo

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.        
  21.         <script type="text/javascript">
  22. //This Function Creates your Cookie for you just pass in the Cookie Name, Value, and number of days before you want it to expire.
  23. function CreateCookie(name,value,days)
  24. {
  25.     if (days)
  26.     {
  27.         var date = new Date();
  28.         date.setTime(date.getTime()+(days*24*60*60*1000));
  29.         var expires = "; expires="+date.toGMTString();
  30.     }
  31.     else var expires = "";
  32.     document.cookie = name + "=" + value + expires + "; path=/";
  33. }
  34.  
  35. //This Function reads the value of a given cookie for you.  Just pass in the cookie name and it will return the value.
  36. function ReadCookie(name)
  37. {
  38.     var nameEQ = name + "=";
  39.     var ca = document.cookie.split(';');
  40.     for(var i=0;i < ca.length;i++) {
  41.         var c = ca[i];
  42.         while (c.charAt(0)==' ') c = c.substring(1,c.length);
  43.         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  44.     }
  45.     return null;
  46. }
  47.  
  48. //This Function Erases Cookies.  Just pass in the name of the cookies you want erased.
  49. function EraseCookie(name)
  50. {
  51.     CreateCookie(name,"",-1);
  52. }
  53.  
  54. //Sets or UnSets Cookies for given checkbox after it's been clicked on/off.
  55. function ChangeBox(CheckBox)
  56. {
  57.     if (document.getElementById(CheckBox).checked)
  58.     {
  59.         var CurrentCookie = ReadCookie("fabletwomaps");
  60.         CurrentCookie = CurrentCookie + CheckBox;  
  61.         CreateCookie("fabletwomaps",CurrentCookie,"100");
  62.     }
  63.     else
  64.     {
  65.         var CurrentCookie = ReadCookie("fabletwomaps");
  66.         CurrentCookie = CurrentCookie.replace(CheckBox,"");
  67.         CreateCookie("fabletwomaps",CurrentCookie,"100");
  68.     }
  69. }
  70. //Runs on body load to check history of checkboxes on the page.
  71. function CheckCookies()
  72. {
  73.     var CurrentCookie = ReadCookie("fabletwomaps");
  74.     for (i=0; i<document.CheckList.elements.length; i++)
  75.     {
  76.         if (document.CheckList.elements[i].type == "checkbox")
  77.         {
  78.             document.CheckList.elements[i].onclick = function() {ChangeBox(this.id);};
  79.            if (CurrentCookie && CurrentCookie.indexOf(document.CheckList.elements[i].id) > -1)
  80.             {
  81.                 document.CheckList.elements[i].checked = true;
  82.             }
  83.         }
  84.     }
  85. }
  86.  
  87. //Clears Form
  88. function ClearBoxes()
  89. {
  90.     for (i=0; i<document.CheckList.elements.length; i++)
  91.     {
  92.         if (document.CheckList.elements[i].type == "checkbox")
  93.         {
  94.             document.CheckList.elements[i].checked = false;
  95.             ChangeBox(document.CheckList.elements[i].id);
  96.         }
  97.     }
  98. }
  99.  
  100. window.onload=CheckCookies;
  101.  
  102.  
  103.        
  104. </head>
  105.  
  106.  
  107. 1 - 12 de 124 imagenes.
  108.  
  109. <form action="compress.php" method="post" id="album" name="CheckList">  
  110. <div id="albumList">
  111.         <div class="albumItem"><div class="albumImg"><img src='img/filter_closed.png' alt='filter_closed.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='filter_closed.png' value='filter_closed.png' onclick='countCheckboxes()' />filter_closed.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=filter_closed.png"></a></div></div>
  112.         <div class="albumItem"><div class="albumImg"><img src='img/folder_up.png' alt='folder_up.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='folder_up.png' value='folder_up.png' onclick='countCheckboxes()' />folder_up.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=folder_up.png"></a></div></div>
  113.         <div class="albumItem"><div class="albumImg"><img src='img/transfer_upload.png' alt='transfer_upload.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='transfer_upload.png' value='transfer_upload.png' onclick='countCheckboxes()' />transfer_upload.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=transfer_upload.png"></a></div></div>
  114.         <div class="albumItem"><div class="albumImg"><img src='img/fitwidth_enabled.png' alt='fitwidth_enabled.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='fitwidth_enabled.png' value='fitwidth_enabled.png' onclick='countCheckboxes()' />fitwidth_enabled.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=fitwidth_enabled.png"></a></div></div>
  115.         <div class="albumItem"><div class="albumImg"><img src='img/dropup.png' alt='dropup.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='dropup.png' value='dropup.png' onclick='countCheckboxes()' />dropup.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=dropup.png"></a></div></div>
  116.  
  117.         <div class="albumItem"><div class="albumImg"><img src='img/search-suggestion.png' alt='search-suggestion.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='search-suggestion.png' value='search-suggestion.png' onclick='countCheckboxes()' />search-suggestion.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=search-suggestion.png"></a></div></div>
  118.         <div class="albumItem"><div class="albumImg"><img src='img/search-suggestion-selected.png' alt='search-suggestion-selected.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='search-suggestion-selected.png' value='search-suggestion-selected.png' onclick='countCheckboxes()' />search-suggestion-selected.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=search-suggestion-selected.png"></a></div></div>
  119.         <div class="albumItem"><div class="albumImg"><img src='img/mail_status_disconnected.png' alt='mail_status_disconnected.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='mail_status_disconnected.png' value='mail_status_disconnected.png' onclick='countCheckboxes()' />mail_status_disconnected.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=mail_status_disconnected.png"></a></div></div>
  120.         <div class="albumItem"><div class="albumImg"><img src='img/group_closed.png' alt='group_closed.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='group_closed.png' value='group_closed.png' onclick='countCheckboxes()' />group_closed.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=group_closed.png"></a></div></div>
  121.         <div class="albumItem"><div class="albumImg"><img src='img/archives.png' alt='archives.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='archives.png' value='archives.png' onclick='countCheckboxes()' />archives.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=archives.png"></a></div></div>
  122.         <div class="albumItem"><div class="albumImg"><img src='img/block.png' alt='block.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='block.png' value='block.png' onclick='countCheckboxes()' />block.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=block.png"></a></div></div>
  123.  
  124.         <div class="albumItem"><div class="albumImg"><img src='img/images_cached.png' alt='images_cached.png'/></div><div class="albumCheck"><label><input type='checkbox' name='addAlbum[]' id='images_cached.png' value='images_cached.png' onclick='countCheckboxes()' />images_cached.png</label></div><div class="albumDownload"><a href="http://psy-tribe.co.cc/download.php?file=images_cached.png"></a></div></div>
  125.          
  126. </div>
  127.  
  128. <span id="checkCount"></span>
  129.  
  130. <input type="submit" name="Submit" value="Enviar">
  131. </form>
  132.  
  133. </body>
  134.  
  135. </html>

Saludos