<?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; JavaScript</title>
	<atom:link href="http://www.mascodigo.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mascodigo.com</link>
	<description>Mantenlo simple, estúpido</description>
	<lastBuildDate>Wed, 14 Sep 2011 14:40:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Creación de un widgets para buscar palabras en la RAE (Real Academia Española )</title>
		<link>http://www.mascodigo.com/2009/09/25/creacion-de-un-widgets-para-buscar-palabras-en-la-rae-real-academia-espanola/</link>
		<comments>http://www.mascodigo.com/2009/09/25/creacion-de-un-widgets-para-buscar-palabras-en-la-rae-real-academia-espanola/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 04:27:55 +0000</pubDate>
		<dc:creator>Webmaster</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[buscador]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[RAE]]></category>

		<guid isPermaLink="false">http://www.mascodigo.com/?p=175</guid>
		<description><![CDATA[En igoogle podemos utilizar un widgets llamado “Buscón R.A.E” que permite buscar palabras en la R.A.E ( Real Academia Española ). Este widgets me pareció útil y decidí crear uno para poder utilizarlo en mis proyectos. A continuación os dejo un ejemplo real funcionando, para que podáis ver como es. Ejemplo real Esta realizado con [...]]]></description>
			<content:encoded><![CDATA[<p>En <strong>igoogle</strong> podemos utilizar un widgets llamado “<strong>Buscón R.A.E</strong>” que permite buscar palabras en la R.A.E ( Real Academia Española ).</p>
<p>Este widgets me pareció útil y decidí crear uno para poder utilizarlo en mis proyectos. A continuación os dejo un ejemplo real funcionando, para que podáis ver como es.</p>
<p><a href="http://archivos.mascodigo.com/ejemplos/buscarRae/buscarenlarae.html" target="_blank">Ejemplo real</a></p>
<p>Esta realizado con javascript y utiliza un iframe para mostrar los resultados. Estos resultados son simplemente una página que devuelve la R.A.E con el significado de la palabra deseada.</p>
<p>El iframe se crea con un ancho del 100% para que se adapte a cualquier lugar donde se inserte. Evidentemente, cada uno puede cambiar las propiedades del iframe, para adaptarlas a sus necesidades.</p>
<p>La única propiedad que no debemos modificar es SRC, porque si cambiamos esta, no obtendremos resultados de búsqueda.</p>
<p>Para terminar dejo el código de este widgets para que podáis insertarlo en vuestra web, blog, &#8230;</p>
<p>JavaScript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #006600; font-style: italic;">/**
             * Esta funcion busca una palabra en la RAE (www.rae.es)
             *
             * @palabra: la palabra que deseamos buscar.
             * @div: elemento div del documento html donde queremos crear
             * el ifram con el resultado de la busqueda.
             */</span>
            <span style="color: #003366; font-weight: bold;">function</span> buscar<span style="color: #009900;">&#40;</span>palabra<span style="color: #339933;">,</span> div<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">//codificar la palabra por si lleva acentos</span>
                palabra <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">encodeURI</span><span style="color: #009900;">&#40;</span>palabra<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">//Generar url a la que debemos llamar para obtener</span>
                <span style="color: #006600; font-style: italic;">//el resultado de buscar dicha palabra en la RAE</span>
                <span style="color: #003366; font-weight: bold;">var</span> url<span style="color: #339933;">;</span>
&nbsp;
                    url <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://buscon.rae.es/draeI/SrvltGUIBusUsual?&quot;</span><span style="color: #339933;">;</span>
                    url <span style="color: #339933;">=</span> url <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;LEMA=&quot;</span> <span style="color: #339933;">+</span> palabra <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&amp;origen=RAE&amp;TIPO_BUS=3&quot;</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #006600; font-style: italic;">//Generar iframe con la página de la RAE</span>
               <span style="color: #003366; font-weight: bold;">var</span> iframe<span style="color: #339933;">;</span>
&nbsp;
                    iframe <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;iframe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">//Añadir atributos al iframe creado</span>
                    iframe.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;scroll&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;auto&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    iframe.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;frameborder&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    iframe.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;width&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;100%&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    iframe.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;height&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;300px&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    iframe.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;src&quot;</span><span style="color: #339933;">,</span> url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #006600; font-style: italic;">//Limpiar el contenido de result</span>
              limpiarDiv<span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #006600; font-style: italic;">//Guardar el iframe creado dentro del div indicado</span>
               <span style="color: #003366; font-weight: bold;">var</span> result<span style="color: #339933;">;</span>
&nbsp;
                       result <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>              
&nbsp;
                    <span style="color: #006600; font-style: italic;">//Añadir al div el iframe con los resultados</span>
                    result.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>iframe<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;">/**
             * Limpiar (eliminar) todos los elementos que contenga
             * el div.
             *
             * @id: identificador del elemento 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></pre></div></div>

<p>Html:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!--
            Buscar con Javascript en la web de la RAE
            www.rae.es
        --&gt;
        &lt;p&gt;
            Buscar: &amp;nbsp;
            &lt;input type=&quot;text&quot; id=&quot;palabra&quot; /&gt; &amp;nbsp;
                &lt;a href=&quot;#&quot;
                   onclick=&quot;buscar(document.getElementById('palabra').value,
                                   'resultado');&quot;&gt; buscar &lt;/a&gt;
        &lt;/p&gt;
        &lt;p&gt;
            &lt;div id=&quot;resultado&quot;&gt;&lt;/div&gt;
        &lt;/p&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mascodigo.com/2009/09/25/creacion-de-un-widgets-para-buscar-palabras-en-la-rae-real-academia-espanola/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>

