<?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>Más código &#187; xhtml</title>
	<atom:link href="http://www.mascodigo.com/tag/xhtml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mascodigo.com</link>
	<description>Keep It Short and Simple</description>
	<lastBuildDate>Fri, 11 May 2012 12:05:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Botón “SELECT” en HTML con los valores de conversión del euro.</title>
		<link>http://www.mascodigo.com/2012/05/11/boton-select-en-html-con-los-valores-de-conversion-del-euro/</link>
		<comments>http://www.mascodigo.com/2012/05/11/boton-select-en-html-con-los-valores-de-conversion-del-euro/#comments</comments>
		<pubDate>Fri, 11 May 2012 12:05:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Documentación]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[banco central europeo]]></category>
		<category><![CDATA[conversión]]></category>
		<category><![CDATA[euro]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[rates]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.mascodigo.com/?p=262</guid>
		<description><![CDATA[A continuación os dejo un código muy sencillo para poder generar un botón “select” con los valores de cada moneda en referencia al euro. Los datos son obtenidos del banco central europeo, por lo tanto los datos estarán siempre actualizados. &#60;?php class RatesEcb &#123; private $_option = &#34;&#34;; &#160; public function __construct&#40;&#41; &#123; &#160; /** [...]]]></description>
			<content:encoded><![CDATA[<p>A continuación os dejo un código muy sencillo para poder generar un botón “select” con los valores de cada moneda en referencia al euro.</p>
<p>Los datos son obtenidos del banco central europeo, por lo tanto los datos estarán siempre actualizados.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> RatesEcb
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_option</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #009933; font-style: italic;">/**
		 * XML con los valores de las monedas según el banco central europeo
		 * http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html
		 */</span>
		<span style="color: #000088;">$xmlFile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cube</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cube</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cube</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_option <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;option value=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cube</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cube</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cube</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;rate&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cube</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cube</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cube</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;currency&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/option&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getSelect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$label</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$other</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$label</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;label for=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$label</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/label&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$select</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;select name=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; id=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;  '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$other</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$select</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_option<span style="color: #339933;">;</span>
		<span style="color: #000088;">$select</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/select&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$select</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Ejemplo de uso</span>
<span style="color: #000088;">$rates</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RatesEcb<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$rates</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rates&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Rates del banco central europeo&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ratesecb&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'onchange=&quot;alert(document.getElementById(\'ratesecb\').value);&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>El código anterior produce esto:<br />
<img src="/wp-content/uploads/rates.png" alt="rates euros" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mascodigo.com/2012/05/11/boton-select-en-html-con-los-valores-de-conversion-del-euro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Borrar y rellenar el contenido de un div con DOM</title>
		<link>http://www.mascodigo.com/2009/08/06/borrar-y-rellenar-el-contenido-de-un-div-con-dom/</link>
		<comments>http://www.mascodigo.com/2009/08/06/borrar-y-rellenar-el-contenido-de-un-div-con-dom/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 16:53:27 +0000</pubDate>
		<dc:creator>Webmaster</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.mascodigo.com/?p=164</guid>
		<description><![CDATA[Cuando utilizamos javascript para modificar contenido en una página, tenemos varias opciones. Una de ellas es innerHTML. Esta opción seria maravillosa, porque permite añadir contenido a un div de forma muy simple, ademas permite añadir código html que sera interpretado como tal. El inconveniente de innerHTML es que no es una función estándar, es decir, [...]]]></description>
			<content:encoded><![CDATA[<p>Cuando utilizamos javascript para modificar contenido en una página, tenemos varias opciones. Una de ellas es innerHTML.</p>
<p>Esta opción seria maravillosa, porque permite añadir contenido a un div de forma muy simple, ademas permite añadir código html que sera interpretado como tal.</p>
<p>El inconveniente de innerHTML es que no es una función estándar, es decir, esta no se especifica en el estándar de javascript (<a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMA-262</a>).</p>
<p>La otra opción es utilizar DOM, de esta forma respetamos el estándar. Por desgracia utilizar DOM es algo mas complicado que innerHTML.</p>
<p>Para solucionar el problema mencionado al principio, manejar contenido con javascript, he creado varias funciones que nos facilitan este trabajo.</p>
<p>Una de ellas se encarga de eliminar todo el contenido de un div y la otra de escribir un texto ( sin código HTML ).</p>
<p>Podéis ver un ejemplo real <a href="http://archivos.mascodigo.com/ejemplos/div/demoDiv.html">aquí</a>.</p>
<p>Funciones:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">        <span style="color: #006600; font-style: italic;">//Eliminar el contenido de un div</span>
        <span style="color: #003366; font-weight: bold;">function</span> limpiarDiv<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> div<span style="color: #339933;">;</span>
&nbsp;
                div <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>div.<span style="color: #660066;">hasChildNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    div.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>div.<span style="color: #660066;">lastChild</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">//Escribir en un div</span>
        <span style="color: #003366; font-weight: bold;">function</span> rellenarDiv<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> texto<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> div<span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> nodoTexto<span style="color: #339933;">;</span>
&nbsp;
              div <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
              nodoTexto <span style="color: #339933;">=</span> document.<span style="color: #660066;">createTextNode</span><span style="color: #009900;">&#40;</span>texto<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
              <span style="color: #006600; font-style: italic;">//Llamamos a la función limpiarDiv para eliminar el contenido</span>
              <span style="color: #006600; font-style: italic;">//actual del div.</span>
              limpiarDiv<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
              div.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>nodoTexto<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mascodigo.com/2009/08/06/borrar-y-rellenar-el-contenido-de-un-div-con-dom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contar caracteres de un campo con JavaScript</title>
		<link>http://www.mascodigo.com/2009/03/25/contar-caracteres-de-un-campo-con-javascript/</link>
		<comments>http://www.mascodigo.com/2009/03/25/contar-caracteres-de-un-campo-con-javascript/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 18:46:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[caracteres]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.mascodigo.com/?p=64</guid>
		<description><![CDATA[Con el fin de hacer las cosas mas fáciles y entendibles al usuario he trabajado un poco la interactividad que tienen estos con los formularios. Al principio no le prestaba mucha atención a este tema. Simplemente creaba un campo con su correspondiente etiqueta descriptiva y ya esta. Ahora para ayudar al usuario a rellenar los [...]]]></description>
			<content:encoded><![CDATA[<p style="margin-bottom: 0cm;">Con el fin de hacer las cosas  mas fáciles y entendibles al usuario he trabajado un poco la interactividad que tienen estos con los formularios.</p>
<p></ br></p>
<p style="margin-bottom: 0cm;">Al principio no le prestaba mucha atención a este tema. Simplemente creaba un campo con su correspondiente etiqueta descriptiva y ya esta.</p>
<p></ br></p>
<p style="margin-bottom: 0cm;">Ahora para ayudar al usuario a rellenar los campos adecuadamente y evitar posibles errores, utilizo una función que indica cuando se paso el número máximo de caracteres, cuantos lleva escritos y añadir un máximo de caracteres permitidos.</p>
<p></ br></p>
<p style="margin-bottom: 0cm;">Esto también da un mayor atractivo al formulario.</p>
<p></ br></p>
<p><a href="http://www.mascodigo.com/ejemplos/contarCaracteresJavaScript/ejemplo.html" target="_blank"><br />
Ejemplo real<br />
</a></p>
<p style="margin-bottom: 0cm;">Ejemplo de uso:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!--</span> incluir fichero con la funcion en JavaScript <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;./contarCaracteres.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/JavaScript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;!--</span>
Campo al que contaremos los caracteres 
&nbsp;
<span style="color: #339933;">*</span> Llamamos a la función con el evento <span style="color: #3366CC;">&quot;onKeyDown&quot;</span>.
<span style="color: #339933;">*</span> Le pasamos como parametros<span style="color: #339933;">:</span>
	<span style="color: #339933;">-</span> el id del campo <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-</span> el id del div donde se mostrara el nº de caracteres actuales
	<span style="color: #339933;">-</span> el color que tendra el campo en caso de sobrepasar el máximo de caracteres
	<span style="color: #339933;">-</span> el máximo de caracteres permitidos.
&nbsp;
<span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;ejemplo&quot;</span> onkeydown<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;contarCaracteres(this.id, 'nCaracteres','#FF0000',10)&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;!--</span> div donde mostraremos el numero de caracteres <span style="color: #339933;">--&gt;</span>
Caracteres<span style="color: #339933;">:&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">'nCaracteres'</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Función:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> contarCaracteres<span style="color: #009900;">&#40;</span>campo<span style="color: #339933;">,</span> id<span style="color: #339933;">,</span>color<span style="color: #339933;">,</span>maximo<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">/**
	 * variable que contiene el div donde vamos a
	 * escribir y borrar.
	 */</span>
	<span style="color: #003366; font-weight: bold;">var</span> div<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * variable que guardara el numero total de
	 * caracteres que tiene el campo que estamos
	 * contando.
	 */</span>
	<span style="color: #003366; font-weight: bold;">var</span> cTotal<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * variable que creara el nodo de texto y el valor
	 * que mostraremos.
	 */</span>
	<span style="color: #003366; font-weight: bold;">var</span> tmp<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//Asignar div al div con el que trabajaremos</span>
	div <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//Borrar el contenido del div</span>
	<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>div.<span style="color: #660066;">hasChildNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		div.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>div.<span style="color: #660066;">lastChild</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//Obtener el número de caracteres del campo en cTotal.</span>
	campo <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>campo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	cTotal <span style="color: #339933;">=</span> campo.<span style="color: #660066;">value</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * Añadirle el atributo maxlenght para evitar que se escriban
	 * mas caracteres de los indicados.
	 */</span>
	campo.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;maxlength&quot;</span><span style="color: #339933;">,</span>maximo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * Si se supera el máximo de caracteres permitidos ponemos el fondo
	 * del campo en rojo ó el color indicado.
	 */</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>cTotal <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> maximo  <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		campo.<span style="color: #660066;">style</span>.<span style="color: #660066;">backgroundColor</span> <span style="color: #339933;">=</span> color<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>  <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		campo.<span style="color: #660066;">style</span>.<span style="color: #660066;">backgroundColor</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#FFFFFF&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * Escribimos el total de caracteres en el div indicado.
	 * Para hacer esto creamos un nodo de texto con el valor de
	 * cTotal. El nodo lo asignamos a tmp
	 */</span>
	tmp <span style="color: #339933;">=</span> document.<span style="color: #660066;">createTextNode</span><span style="color: #009900;">&#40;</span>cTotal<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//Añadimos el contenido de tmp al div indicado.</span>
	div.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>tmp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mascodigo.com/2009/03/25/contar-caracteres-de-un-campo-con-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

