<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TolerantX&#039;s Blog &#187; funcion</title>
	<atom:link href="http://tolerantx.com/tag/funcion/feed/" rel="self" type="application/rss+xml" />
	<link>http://tolerantx.com</link>
	<description>Y sin embargo se mueve</description>
	<lastBuildDate>Mon, 28 Feb 2011 02:16:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Checkbox: Seleccionar, deseleccionar todos</title>
		<link>http://tolerantx.com/2010/04/06/checkbox-seleccionar-deseleccionar-todos/</link>
		<comments>http://tolerantx.com/2010/04/06/checkbox-seleccionar-deseleccionar-todos/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 04:16:34 +0000</pubDate>
		<dc:creator>TolerantX</dc:creator>
				<category><![CDATA[Informática]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[funcion]]></category>
		<category><![CDATA[seleccionar todos]]></category>

		<guid isPermaLink="false">http://tolerantx.com/?p=332</guid>
		<description><![CDATA[Sé que hay muchos ejemplos,]]></description>
			<content:encoded><![CDATA[<p>Sé que hay muchos ejemplos, guias etc sobre como seleccionar o deseleccionar checkbox en una página web con javascript, pero pocos hacen referencia a hacer una función un poco más generica donde abarque tanto el nombre del formulario, el nombre de elementos a seleccionar y la casilla &#8220;todos&#8221; también con checkbox.</p>
<p>Tenemos 2 funciones javascript, una que se encarga de seleccionar todos los &#8220;checkbox&#8221; y la otra función que se encarga de verificar si permanece seleccionado nuestro checkbox que selecciona &#8220;todos&#8221;:<span id="more-332"></span></p>
<pre  name="code"  class="javascript">function checkElements(form, elementAll, elementToCheck) {
    var form, checkbox = form.elements[elementToCheck];
    totalElements = checkbox.length;
    checkboxAll = form.elements[elementAll];

    for(var n=0; n&lt;totalElements; n++) {
        checkbox[n].checked = checkboxAll.checked;
    }
}

function checkElementAll(form, elementAll, elementCheck) {
    var form, counter=0;
    checkbox = form.elements[elementCheck];
    checkboxAll = form.elements[elementAll];
    totalElements = checkbox.length;

    for(var n=0; n&lt;totalElements; n++) {
        if (checkbox[n].checked == true) counter++;
    }
    if (totalElements &gt; counter)
        checkboxAll.checked = false;
    else
        checkboxAll.checked = true;
}
</pre>
<p>Y un ejemplo de formulario sería algo como lo siguiente:</p>
<pre name="code" class="xml">&lt;form name="nombreFormulario" method="post" action=""&gt;
    &lt;p&gt;&lt;input type="checkbox" name="selecciona_todos" onclick="checkElements(this.form, this.name, 'frutas[]')" /&gt;&lt;label&gt;Todos&lt;/label&gt;&lt;/p&gt;
    &lt;p&gt;&lt;input type="checkbox" name="frutas[]" value="manzana" onclick="checkElementAll(this.form, 'selecciona_todos', this.name)" /&gt;&lt;label&gt;Manzana&lt;/label&gt;&lt;/p&gt;
    &lt;p&gt;&lt;input type="checkbox" name="frutas[]" value="mango" onclick="checkElementAll(this.form, 'selecciona_todos', this.name)" /&gt;&lt;label&gt;Mango&lt;/label&gt;&lt;/p&gt;
    &lt;p&gt;&lt;input type="checkbox" name="frutas[]" value="pera" onclick="checkElementAll(this.form, 'selecciona_todos', this.name)" /&gt;&lt;label&gt;Pera&lt;/label&gt;&lt;/p&gt;
    &lt;p&gt;&lt;input type="checkbox" name="frutas[]" value="sandia" onclick="checkElementAll(this.form, 'selecciona_todos', this.name)" /&gt;&lt;label&gt;Sandia&lt;/label&gt;&lt;/p&gt;
    &lt;p&gt;&lt;input type="checkbox" name="frutas[]" value="naranja" onclick="checkElementAll(this.form, 'selecciona_todos', this.name)" /&gt;&lt;label&gt;Naranja&lt;/label&gt;&lt;/p&gt;
&lt;/form&gt;</pre>
<p> <img src='http://tolerantx.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://tolerantx.com/2010/04/06/checkbox-seleccionar-deseleccionar-todos/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

