<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>ProDev</title>
	
	<link>http://prodev.cl</link>
	<description>Ingeniería Informática</description>
	<lastBuildDate>Fri, 02 Oct 2009 15:56:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Prodev" /><feedburner:info uri="prodev" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Como agregar filas o rows a una tabla dinamicamente mediante jQuery</title>
		<link>http://feedproxy.google.com/~r/Prodev/~3/WUpu9aMJ_NY/</link>
		<comments>http://prodev.cl/2009/09/como-agregar-filas-o-rows-a-una-tabla-dinamicamente-mediante-jquery/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 20:04:00 +0000</pubDate>
		<dc:creator>eALL</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[agregar-fila]]></category>
		<category><![CDATA[dinamico]]></category>

		<guid isPermaLink="false">http://prodev.cl/?p=158</guid>
		<description><![CDATA[En el post anterior Como agregar filas o rows a una tabla dinamicamente mediante JavaScript mostré una manera como agregar filas a una tabla (aplicable a cualquier elemento) utilizando JavaScript. Ahora veremos de que manera podemos hacerlo con jQuery, un Framework bastante sencillo de utiliza, pero no menos potente por ello.
La base es crear una [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/jPujUoH1Fja7I_5reyLIyxi4D4w/0/da"><img src="http://feedads.g.doubleclick.net/~a/jPujUoH1Fja7I_5reyLIyxi4D4w/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/jPujUoH1Fja7I_5reyLIyxi4D4w/1/da"><img src="http://feedads.g.doubleclick.net/~a/jPujUoH1Fja7I_5reyLIyxi4D4w/1/di" border="0" ismap="true"></img></a></p><p>En el post anterior <a href="http://prodev.cl/2009/09/como-agregar-filas-o-rows-a-una-tabla-dinamicamente-mediante-javascript/">Como agregar filas o rows a una tabla dinamicamente mediante JavaScript</a> mostré una manera como agregar filas a una tabla (aplicable a cualquier elemento) utilizando JavaScript. Ahora veremos de que manera podemos hacerlo con jQuery, un Framework bastante sencillo de utiliza, pero no menos potente por ello.<br />
La base es crear una cadena con el HTML que irá dentro de la fila o TR de nuestra tabla. Queda más o menos así.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> agregarFila<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#cant_campos&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#cant_campos&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> oId <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#cant_campos&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	<span style="color: #003366; font-weight: bold;">var</span> nombre <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#txtNombre&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> edad <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#txtEdad&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> direccion <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#txtDireccion&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> sexo <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#selSexo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> estCivil <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#selEstCivil&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	<span style="color: #003366; font-weight: bold;">var</span> strHtml1 <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span> <span style="color: #339933;">+</span> nombre <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;input type=&quot;hidden&quot; id=&quot;hdnNombre_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;  name=&quot;hdnNombre_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; value=&quot;'</span> <span style="color: #339933;">+</span> nombre <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;/&gt;&lt;/td&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> strHtml2 <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span> <span style="color: #339933;">+</span> edad <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;input type=&quot;hidden&quot; id=&quot;hdnEdad_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; name=&quot;hdnEdad_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; value=&quot;'</span> <span style="color: #339933;">+</span> edad <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;/&gt;&lt;/td&gt;'</span> <span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> strHtml3 <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span> <span style="color: #339933;">+</span> direccion <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;input type=&quot;hidden&quot; id=&quot;hdnDireccion_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; name=&quot;hdnDireccion_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; value=&quot;'</span> <span style="color: #339933;">+</span> direccion <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;/&gt;&lt;/td&gt;'</span> <span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> strHtml4 <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span> <span style="color: #339933;">+</span> sexo <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;input type=&quot;hidden&quot; id=&quot;hdnSexo_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; name=&quot;hdnSexo_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; value=&quot;'</span> <span style="color: #339933;">+</span> sexo <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;/&gt;&lt;/td&gt;'</span> <span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> strHtml5 <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span> <span style="color: #339933;">+</span> estCivil <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;input type=&quot;hidden&quot; id=&quot;hdnEstCivil_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; name=&quot;hdnEstCivil_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; value=&quot;'</span> <span style="color: #339933;">+</span> estCivil <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;/&gt;&lt;/td&gt;'</span> <span style="color: #339933;">;</span>
    		<span style="color: #003366; font-weight: bold;">var</span> strHtml6 <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;td&gt;&lt;img src=&quot;images/delete.png&quot; width=&quot;16&quot; height=&quot;16&quot; alt=&quot;Eliminar&quot; onclick=&quot;if(confirm(<span style="color: #000099; font-weight: bold;">\'</span>Realmente desea eliminar este detalle?<span style="color: #000099; font-weight: bold;">\'</span>)){eliminarFila('</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">');}&quot;/&gt;'</span><span style="color: #339933;">;</span>
        	strHtml6 <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;input type=&quot;hidden&quot; id=&quot;hdnIdCampos_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; name=&quot;hdnIdCampos[]&quot; value=&quot;'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; /&gt;&lt;/td&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-158"></span></p>
<p>Una vez hecho esto procedemos a agregar la fila al formulario y luego le asignamos el HTML creado anteriormente</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">		<span style="color: #003366; font-weight: bold;">var</span> strHtmlTr <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;tr id='rowDetalle_&quot;</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
        	<span style="color: #003366; font-weight: bold;">var</span> strHtmlFinal <span style="color: #339933;">=</span> strHtml1 <span style="color: #339933;">+</span> strHtml2 <span style="color: #339933;">+</span> strHtml3 <span style="color: #339933;">+</span> strHtml4 <span style="color: #339933;">+</span> strHtml5 <span style="color: #339933;">+</span> strHtml6<span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#tbDetalle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>strHtmlTr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#rowDetalle_&quot;</span> <span style="color: #339933;">+</span> oId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>strHtmlFinal<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>y para eliminar una fila</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	<span style="color: #003366; font-weight: bold;">function</span> eliminarFila<span style="color: #009900;">&#40;</span>oId<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#rowDetalle_&quot;</span> <span style="color: #339933;">+</span> oId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Muy sencillo y no requiere grandes conocimiento en ningún lenguaje en particular.<br />
Espero le sea de ayuda y recuerden que estoy atento a sus comentarios.</p>
<p>Este ejemplo lo puedes ver en el siguiente enlace:</p>
<table border="0">
<tbody>
<tr>
<td><img src="http://prodev.cl/images/ejecutar.png" alt="Ver Ejemplo" width="48" height="48" /></td>
<td><a href="http://prodev.cl/tutoriales/agregarfilajquery.php" target="_blank">ejemplo funcionando de</a> Agregar Filas con JavaScript</td>
</tr>
</tbody>
</table>
<p>Tambien puedes decargar estos ejemplos:</p>
<table border="0">
<tbody>
<tr>
<td><img src="http://prodev.cl/images/comp.png" alt="Ver Ejemplo" width="48" height="48" /></td>
<td><a href="http://prodev.cl/tutoriales/agregarfilajquery.zip" target="_blank">archivos de</a> Agregar Filas con JavaScript</td>
</tr>
<tr>
<td colspan="2"><strong>Si te gustó o te sirvió, ya sabes que hacer <img src='http://prodev.cl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </strong></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://prodev.cl/2009/09/como-agregar-filas-o-rows-a-una-tabla-dinamicamente-mediante-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://prodev.cl/2009/09/como-agregar-filas-o-rows-a-una-tabla-dinamicamente-mediante-jquery/</feedburner:origLink></item>
		<item>
		<title>Como agregar filas o rows a una tabla dinamicamente mediante javaScript</title>
		<link>http://feedproxy.google.com/~r/Prodev/~3/23d6tFP9kSw/</link>
		<comments>http://prodev.cl/2009/09/como-agregar-filas-o-rows-a-una-tabla-dinamicamente-mediante-javascript/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 19:55:23 +0000</pubDate>
		<dc:creator>eALL</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[agregar-fila]]></category>
		<category><![CDATA[dinamico]]></category>

		<guid isPermaLink="false">http://prodev.cl/?p=154</guid>
		<description><![CDATA[Uno de los post más visitados y más agradecidos es el de agregar filas dinamicamente con xajax. En este mucho se topan con la desdicha que no quieren utilizar xajax en sus proyecto proque no quieren o utilizan otro lenguaje para trabajar que no es PHP que es el lenguaje que se utiliza para xajax. [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/hh4OghL70DvWnBQ3v6HDRnMqM2s/0/da"><img src="http://feedads.g.doubleclick.net/~a/hh4OghL70DvWnBQ3v6HDRnMqM2s/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/hh4OghL70DvWnBQ3v6HDRnMqM2s/1/da"><img src="http://feedads.g.doubleclick.net/~a/hh4OghL70DvWnBQ3v6HDRnMqM2s/1/di" border="0" ismap="true"></img></a></p><p style="text-align: justify;">Uno de los post más visitados y más agradecidos es el de <a href="http://prodev.cl/2009/01/como-agregar-filas-rows-tabla-dinamicamente-mediante-xajax/" target="_blank">agregar filas dinamicamente con xajax</a>. En este mucho se topan con la desdicha que no quieren utilizar xajax en sus proyecto proque no quieren o utilizan otro lenguaje para trabajar que no es PHP que es el lenguaje que se utiliza para xajax. Bueno, para todos aquellos que les sucede esto, he preparado un pequeño ejemplo de como se podría hacer lo mismo desde javascript sin ningún framework. Vamos allá.</p>
<p><span id="more-154"></span></p>
<p style="text-align: justify;">La solución es muy similar a la anterior. Se crea una fila mediante el comando <em><strong>createElement</strong></em> y luego se añade al DOM mediante <em><strong>appendChild</strong></em>. Por supuesto he agregado un control de filas para poder eliminar una fila desde cualquier posición.<br />
 un ejemplo de lo que digo es el siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> agregarFila<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	obj.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//aumentamos el id de los campos</span>
	<span style="color: #003366; font-weight: bold;">var</span> oId <span style="color: #339933;">=</span> obj.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//esto hay que hacerlo para cada campo.</span>
	<span style="color: #003366; font-weight: bold;">var</span> nombre <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;txtNombre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//uno de los campos</span>
	<span style="color: #003366; font-weight: bold;">var</span> strHtml1 <span style="color: #339933;">=</span> nombre.<span style="color: #660066;">value</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'
&lt;input id=&quot;hdnNombre_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; name=&quot;hdnNombre_'</span> <span style="color: #339933;">+</span> oId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; type=&quot;hidden&quot; value=&quot;'</span> <span style="color: #339933;">+</span> nombre.<span style="color: #660066;">value</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; /&gt;'</span> <span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// html a agregar</span>
	<span style="color: #003366; font-weight: bold;">var</span> objTr <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tr&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//se crea una fila</span>
	objTr.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;rowDetalle_&quot;</span> <span style="color: #339933;">+</span> oId<span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//asignamos una id para manipularlo despues.</span>
	<span style="color: #003366; font-weight: bold;">var</span> objTd1 <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;td&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//creamos cada td</span>
	objTd1.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;tdDetalle_1_&quot;</span> <span style="color: #339933;">+</span> oId<span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//asignamos una id</span>
	objTd1.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> strHtml1<span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// asignamos el html al td</span>
	objTr.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>objTd1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// agregamos el td a la fila</span>
	<span style="color: #003366; font-weight: bold;">var</span> objTbody <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tbDetalle&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//Seleccionamos el contenedor de las filas</span>
	objTbody.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>objTr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// agregamos la fila al contenedor</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//evita que haya un submit por equivocacion.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;">Para eliminar una de las filas el proceso es algo similar aunque no por ello más complicado. Se debe seleccionar el objeto a eliminar, averiguar su pardre y decirle a este que elimine el objeto deseado mediante el metodo <em><strong>removeChild</strong></em>. veamos como se hace</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> cancelar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tbDetalle'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> objPadre <span style="color: #339933;">=</span> obj.<span style="color: #660066;">parentNode</span><span style="color: #339933;">;</span>
	objPadre.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	obj <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tbody&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	obj.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'tbDetalle'</span><span style="color: #339933;">;</span>
	objPadre.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;">Espero que les sirva y que lo puedan utilizar. Si se les ocurre alguna mejora, o quieren comentar algo, solo haganlo.</p>
<p>Este ejemplo lo puedes ver en el siguiente enlace:</p>
<table border="0">
<tbody>
<tr>
<td><img src="http://prodev.cl/images/ejecutar.png" alt="Ver Ejemplo" width="48" height="48" /></td>
<td><a href="http://prodev.cl/tutoriales/agregarfilajs.php" target="_blank">ejemplo funcionando de</a> Agregar Filas con JavaScript</td>
</tr>
</tbody>
</table>
<p>Tambien puedes decargar estos ejemplos:</p>
<table border="0">
<tbody>
<tr>
<td><img src="http://prodev.cl/images/comp.png" alt="Ver Ejemplo" width="48" height="48" /></td>
<td><a href="http://prodev.cl/tutoriales/agregarfilajs.zip" target="_blank">archivos de</a> Agregar Filas con JavaScript</td>
</tr>
<tr>
<td colspan="2"><strong>Si te gustó o te sirvió, ya sabes que hacer <img src='http://prodev.cl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </strong></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://prodev.cl/2009/09/como-agregar-filas-o-rows-a-una-tabla-dinamicamente-mediante-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://prodev.cl/2009/09/como-agregar-filas-o-rows-a-una-tabla-dinamicamente-mediante-javascript/</feedburner:origLink></item>
		<item>
		<title>Actualizando Wordpress</title>
		<link>http://feedproxy.google.com/~r/Prodev/~3/TsbpsBRuvS4/</link>
		<comments>http://prodev.cl/2009/07/actualizando-wordpress/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 12:29:27 +0000</pubDate>
		<dc:creator>eALL</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://prodev.cl/?p=150</guid>
		<description><![CDATA[En pro de una apariencia un poco más corporativa, he desidido actualizar el blog y crear una nueva plantilla según los colores de mi pseudoempresa, por lo que si algo no anda como corresponde o la pagina cambia repentinamente es porque estoy trabajando.
Agradeciendo su comprensión y sus visitas, y esperando que me ayuden en cuanto [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/pkKGOlvTjz0-w2RzO-0zbAvzvmM/0/da"><img src="http://feedads.g.doubleclick.net/~a/pkKGOlvTjz0-w2RzO-0zbAvzvmM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/pkKGOlvTjz0-w2RzO-0zbAvzvmM/1/da"><img src="http://feedads.g.doubleclick.net/~a/pkKGOlvTjz0-w2RzO-0zbAvzvmM/1/di" border="0" ismap="true"></img></a></p><p>En pro de una apariencia un poco más corporativa, he desidido actualizar el blog y crear una nueva plantilla según los colores de mi pseudoempresa, por lo que si algo no anda como corresponde o la pagina cambia repentinamente es porque estoy trabajando.</p>
<p>Agradeciendo su comprensión y sus visitas, y esperando que me ayuden en cuanto a lo visual ya que no soy nada bueno en el diseño, me despido.</p>
<p>Exito.</p>
]]></content:encoded>
			<wfw:commentRss>http://prodev.cl/2009/07/actualizando-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://prodev.cl/2009/07/actualizando-wordpress/</feedburner:origLink></item>
		<item>
		<title>Como utilizar autocompletex (suggest) de jQuery y no morir en el intento.</title>
		<link>http://feedproxy.google.com/~r/Prodev/~3/13mLHOqJ5Q0/</link>
		<comments>http://prodev.cl/2009/04/como-utilizar-autocompletex-suggest-de-jquery-y-no-morir-en-el-intento/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 19:27:00 +0000</pubDate>
		<dc:creator>eALL</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[autocompletar]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[suggest]]></category>

		<guid isPermaLink="false">http://prodev.cl/?p=138</guid>
		<description><![CDATA[Un aditivo para nuestras paginas webs o formularios es agregar la funcionalidad de autocompletar o sugerir los resultados en un campo de texto, especialmente cuando la cantidad de resultados es demasiado grande como para colocarla dentro de select.
Uno de los más completos que he podido ver y el cual he adoptado en la mayoría de [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/IZfs0yh4CKhrKUyZWczSXlAjUbA/0/da"><img src="http://feedads.g.doubleclick.net/~a/IZfs0yh4CKhrKUyZWczSXlAjUbA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/IZfs0yh4CKhrKUyZWczSXlAjUbA/1/da"><img src="http://feedads.g.doubleclick.net/~a/IZfs0yh4CKhrKUyZWczSXlAjUbA/1/di" border="0" ismap="true"></img></a></p><p class="MsoNormal"><span lang="ES-CL">Un aditivo para nuestras paginas webs o formularios es agregar la funcionalidad de autocompletar o sugerir los resultados en un campo de texto, especialmente cuando la cantidad de resultados es demasiado grande como para colocarla dentro de select.</span></p>
<p class="MsoNormal"><span lang="ES-CL">Uno de los más completos que he podido ver y el cual he adoptado en la mayoría de los proyecto que he llevado a cabo es el plugin de jQuery <strong>autocompletex de </strong></span><span class="submitted"><a title="View user profile." href="http://plugins.jquery.com/user/5">Jörn Zaefferer</a></span><strong><span lang="ES-CL"><span> </span><a href="http://plugins.jquery.com/project/autocompletex">http://plugins.jquery.com/project/autocompletex</a></span></strong></p>
<p class="MsoNormal"><span lang="ES-CL">Este plugin es muy completo. Te permite enviar parámetros extra, recibir más de un parámetro a través de un arreglo, soporte para hacer las consultas asincrónicamente, consultar desde prácticamente cualquier archivo o script que genere una salida formateada como lo indica el plugin, entre otras.</span></p>
<p class="MsoNormal"><span lang="ES-CL"> En este tutorial me enfocaré a las consultas a través de PHP y MySQL, rescatando las opciones desde una BD y devolviendo los resultados al formulario que lo solicita y llenaremos más de un campo con los resultados obtenidos.</span></p>
<p class="MsoNormal"><span lang="ES-CL"> Vamos a la acción. Utilizando uno de los formularios utilizados anteriormente rescataremos información de personas utilizando autocomplete en el campo nombre.<br/><br />
El funcionamiento es bastante sencillo. El plugin llama mediante ajax a un archivo que genera un arreglo. la clave de todo est&aacute; en que env&iacute;a un parametro por metodo GET con el nombre &#8216;q&#8217; (supongo que viene del ingles query) el cual contiene los caracteres tipeados por el usuario. Con este valor podremos filtrar nuestra consulta y generar una especie de arreglo que despues llegar&aacute; a JS con el nombre data. En la primera posici&oacute;n estar&aacute; lo que se muestra en el listado desplegable y de la segunda en adelante podremos utilizarla a gusto. Veamos un ejemplo.<br />
</span></p>
<p class="MsoNormal"><span lang="ES-CL">Para esto debemos agregar los script necesarios y lo típico para utilizar jQuery.</span></p>
<p class="MsoNormal"><span lang="ES-CL"> Las inclusiones:</span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/jquery.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/jquery.autocomplete.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/jquery.autocomplete.css&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/jquerymenu/jqueryslidemenu.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/jquery.autocomplete.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p class="MsoNormal"><span lang="ES-CL"> El código de la llamada:</span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> <span style="color: #339933;">&gt;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#txtNombre'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'search.php?tip=a&amp;opt=1'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//ID DEL CAMPO QUE SERA AUTOCOMPLETABLE</span>
            width<span style="color: #339933;">:</span> <span style="color: #CC0000;">260</span><span style="color: #339933;">,</span>
            selectFirst<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p class="MsoNormal"><span lang="ES-CL"> El PHP que genera el resultado</span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;conexion/class.conexionDB.inc.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conn</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> conexionBD <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">extract</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Consulta a Bases de datos. */</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$tip</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$tip</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'a'</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: #000088;">$opt</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot; SELECT DISTINCT
                    PER_NOMBRE,
                    PER_EDAD,
                    PER_DIRECCION,
                    PER_SEXO,
                    PER_ESTCIVIL
                FROM
                    PERSONA&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot; WHERE
                        (PER_NOMBRE like N'%<span style="color: #006699; font-weight: bold;">$q</span>%')  &quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$sp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EjecutarSQL</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sql</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//$separador = &quot;MOD: &quot;;</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$row5</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FetchArray</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sp</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">trim</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$row5</span> <span style="color: #009900;">&#91;</span>PER_NOMBRE<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; <span style="color: #006699; font-weight: bold;">$row5[PER_EDAD]</span> - <span style="color: #006699; font-weight: bold;">$row5[PER_SEXO]</span>&quot;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//LO QUE SERA MOSTRADO EN EL RECUADRO DESPLEGABLE</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'|'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">trim</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$row5</span> <span style="color: #009900;">&#91;</span>PER_NOMBRE<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//LO QUE ASIGNAREMOS AL CAMPO NOMBRE</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'|'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">trim</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$row5</span> <span style="color: #009900;">&#91;</span>PER_EDAD<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'|'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">trim</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$row5</span> <span style="color: #009900;">&#91;</span>PER_DIRECCION<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'|'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">trim</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$row5</span> <span style="color: #009900;">&#91;</span>PER_SEXO<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'|'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">trim</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$row5</span> <span style="color: #009900;">&#91;</span>PER_ESTCIVIL<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><span id="more-138"></span></p>
<p class="MsoNormal"><span lang="ES-CL"> Las acciones a realizar una vez devuelto los valores:</span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">        result<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> formatted<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#txtNombre'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#txtEdad'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#txtDireccion'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#selSexo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#selEstCivil'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p class="MsoNormal"><span lang="ES-CL"> La llamada completa desde jQuery es:</span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> <span style="color: #339933;">&gt;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#txtNombre'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'search.php?tip=a&amp;opt=1'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
            width<span style="color: #339933;">:</span> <span style="color: #CC0000;">260</span><span style="color: #339933;">,</span>
            selectFirst<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">result</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> formatted<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#txtNombre'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#txtEdad'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#txtDireccion'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#selSexo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#selEstCivil'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p class="MsoNormal"><span lang="ES-CL"> Como ves, los limites pueden crecer al limite de tu imaginación. Solo hay que saber como organizar los datos y presentarlos en tu formulario.</span></p>
<p class="MsoNormal"><span lang="ES-CL">Espero que les sirva.</span></p>
<p class="MsoNormal"><span lang="ES-CL">Disfrútenlo y cualquier duda o comentario no teman en escribir.</span></p>
<p class="MsoNormal"><span lang="ES-CL"> </span></p>
<p class="MsoNormal"><span lang="ES-CL">Éxito.</span></p>
<p><br class="spacer_" /></p>
<p>Este ejemplo lo puedes ver en el siguiente enlace:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/ejecutar.png" width="48" height="48" alt="Ver Ejemplo" />
</td>
<td><a href="http://prodev.cl/tutoriales/autocompletex.php" target="_blank">ejemplo funcionando de</a> Como utilizar autocompletex (suggest) de jQuery y no morir en el intento.
   </td>
</tr>
</table>
<p>Tambien puedes decargar estos ejemplos:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/comp.png" width="48" height="48" alt="Ver Ejemplo" />
   </td>
<td><a href="http://prodev.cl/tutoriales/autocompletex.zip" target="_blank">archivos de </a> Como utilizar autocompletex (suggest) de jQuery y no morir en el intento.
   </td>
</tr>
<tr>
<td colspan="2"><b>Si te gust&oacute; o te sirvi&oacute;, ya sabes que hacer <img src='http://prodev.cl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </b></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://prodev.cl/2009/04/como-utilizar-autocompletex-suggest-de-jquery-y-no-morir-en-el-intento/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		<feedburner:origLink>http://prodev.cl/2009/04/como-utilizar-autocompletex-suggest-de-jquery-y-no-morir-en-el-intento/</feedburner:origLink></item>
		<item>
		<title>Guardar en Base de Datos las filas agregadas dinamicamente con xajax</title>
		<link>http://feedproxy.google.com/~r/Prodev/~3/kTDnys7ten4/</link>
		<comments>http://prodev.cl/2009/03/guardar-datos-en-base-de-datos-las-filas-agregadas-dinamicamente-con-xajax/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 00:01:26 +0000</pubDate>
		<dc:creator>eALL</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[xajax]]></category>
		<category><![CDATA[agregar-fila-dinamico-xajax]]></category>
		<category><![CDATA[dinamico]]></category>

		<guid isPermaLink="false">http://prodev.cl/?p=114</guid>
		<description><![CDATA[Para este tutorial utilizaremos el conocimiento adquirido en el tutorial anterior http://prodev.cl/2009/01/como-agregar-filas-rows-tabla-dinamicamente-mediante-xajax/ .Lo que haremos será guardar los datos necesarios en campos ocultos y luego rescatarlos desde xajax y enviarlos a una función en PHP que los guarde en una Base de Datos.
Para comenzar, debemos modificar el código anterior y agregar en campos ocultos los [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/j9neT0EUZu_rnj26wSODd7UM-ek/0/da"><img src="http://feedads.g.doubleclick.net/~a/j9neT0EUZu_rnj26wSODd7UM-ek/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/j9neT0EUZu_rnj26wSODd7UM-ek/1/da"><img src="http://feedads.g.doubleclick.net/~a/j9neT0EUZu_rnj26wSODd7UM-ek/1/di" border="0" ismap="true"></img></a></p><p class="MsoNormal"><span lang="ES-CL">Para este tutorial utilizaremos el conocimiento adquirido en el tutorial anterior <a href="../2009/01/como-agregar-filas-rows-tabla-dinamicamente-mediante-xajax/">http://prodev.cl/2009/01/como-agregar-filas-rows-tabla-dinamicamente-mediante-xajax/</a> .<br />Lo que haremos será guardar los datos necesarios en campos ocultos y luego rescatarlos desde xajax y enviarlos a una función en PHP que los guarde en una Base de Datos.</span></p>
<p class="MsoNormal"><span lang="ES-CL">Para comenzar, debemos modificar el código anterior y agregar en campos ocultos los valores extraídos del formulario añadiendo al nombre el número de línea al que corresponde el detalle de la siguiente manera:</span></p>
<p class="MsoNormal"><span lang="ES-CL">hdn(nombreCampo)_(numeroLinea)</span></p>
<p class="MsoNormal"><span lang="ES-CL">por lo que nuestro código quedaría de la siguiente forma:</span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$id_campos</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cant_campos</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$num_campos</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$str_html_td1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$txtNombre</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'
&lt;input type=&quot;hidden&quot; id=&quot;hdnNombre_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; name=&quot;hdnNombre_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$txtNombre</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;/&gt;'</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$txtEdad</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'
&lt;input type=&quot;hidden&quot; id=&quot;hdnEdad_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; name=&quot;hdnEdad_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$txtEdad</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;/&gt;'</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$txtDireccion</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'
&lt;input type=&quot;hidden&quot; id=&quot;hdnDireccion_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; name=&quot;hdnDireccion_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$txtDireccion</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;/&gt;'</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td4</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$selSexo</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'
&lt;input type=&quot;hidden&quot; id=&quot;hdnSexo_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; name=&quot;hdnSexo_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$selSexo</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;/&gt;'</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td5</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$selEstCivil</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'
&lt;input type=&quot;hidden&quot; id=&quot;hdnEstCivil_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; name=&quot;hdnEstCivil_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$selEstCivil</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;/&gt;'</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td6</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;images/delete.png&quot; width=&quot;16&quot; height=&quot;16&quot; alt=&quot;Eliminar&quot; onclick=&quot;if(confirm(\'Realmente desea eliminar este detalle?\')){xajax_eliminarFila('</span><span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">', proyecto.cant_campos.value);}&quot;/&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-114"></span></p>
<p class="MsoNormal"><span lang="ES-CL">Además debemos agregar un campo oculto que contenga el número de línea correspondiente y le damos el nombre hdnIdCampos[] esto hará que se cree un arreglo de inputs llamados “hdnIdCampos” los cuales accederemos desde PHP. Lo podemos agregar a la &uacute;ltima l&iacute;nea.</span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$str_html_td6</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;images/delete.png&quot; width=&quot;16&quot; height=&quot;16&quot; alt=&quot;Eliminar&quot; onclick=&quot;if(confirm(\'Realmente desea eliminar este detalle?\')){xajax_eliminarFila('</span><span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">', proyecto.cant_campos.value);}&quot;/&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td6</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'
&lt;input type=&quot;hidden&quot; id=&quot;hdnIdCampos_'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; name=&quot;hdnIdCampos[]&quot; value=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; /&gt;</span></pre></div></div>

<p class="MsoNormal"><span lang="ES-CL">Aquí podemos ver el HTML generado dinámicamente por nuestra aplicación.</span></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tblDetalle&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;listado&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100%&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tbody</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tbDetalle&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rowDetalle_0&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_01&quot;</span>&gt;</span>Nombre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_02&quot;</span>&gt;</span>Edad<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_03&quot;</span>&gt;</span>Direccion<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_04&quot;</span>&gt;</span>Sexo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_05&quot;</span>&gt;</span>Estado Civil<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_06&quot;</span>&gt;</span>Eliminar<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rowDetalle_1&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_11&quot;</span>&gt;</span>eall
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnNombre_1&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnNombre_1&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;eall&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_12&quot;</span>&gt;</span>25
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnEdad_1&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnEdad_1&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_13&quot;</span>&gt;</span>mi casa
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnDireccion_1&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnDireccion_1&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mi casa&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_14&quot;</span>&gt;</span>Hombre
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnSexo_1&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnSexo_1&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Hombre&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_15&quot;</span>&gt;</span>Soltero
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnEstCivil_1&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnEstCivil_1&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Soltero&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tdDetalle_16&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/delete.png&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Eliminar&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;if(confirm('Realmente desea eliminar este detalle?')){xajax_eliminarFila(1, proyecto.cant_campos.value);}&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;16&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnIdCampos_1&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hdnIdCampos[]&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></pre></div></div>

<p class="MsoNormal"><span lang="ES-CL">Lo que sigue es crea una función que tome los valores de cada una de las filas o rows agregados y los guarde en la Base de Datos. Para esto aprovecharemos la bondad de PHP que nos permite tener arreglos con índices de tipo string y, construiremos los índices tomando el nombre del campo más el número de línea <span> </span>que guardamos en “hdnIdCampos”.</span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> guardar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$formulario</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//comentaré todo lo que tenga que ver con la Base de Datos</span>
    <span style="color: #000088;">$flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$formulario</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$respuesta</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xajaxResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//    $conn = new conexionBD ( ); //Genera una nueva coneccion</span>
<span style="color: #666666; font-style: italic;">//	$conn-&gt;EjecutarSQL(&quot;BEGIN TRANSACTION A1&quot;);</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hdnIdCampos</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>      <span style="color: #666666; font-style: italic;">// Así recorro cada campo en cada linea</span>
<span style="color: #666666; font-style: italic;">//	Guardo la consulta en una cadena</span>
        <span style="color: #000088;">$Str_SQL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO PERSONAS(
                        NOMBRE, EDAD, DIRECCION,
                        SEXO, ESTCIVIL)
                        VALUES(
                        &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$formulario</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hdnNombre_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;, &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$formulario</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hdnEdad_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;, &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$formulario</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hdnDireccion_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;,
                        &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$formulario</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hdnSexo_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$formulario</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hdnEstCivil_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//        if(!$conn-&gt;EjecutarSQL($Str_SQL)){  //CONTROL DE ERRORES.  muy importante, si no guarda uno, no guarda nada.</span>
<span style="color: #666666; font-style: italic;">//            $conn-&gt;EjecutarSQL(&quot;ROLLBACK TRANSACTION A1&quot;);</span>
<span style="color: #666666; font-style: italic;">//            $flag = 1;</span>
<span style="color: #666666; font-style: italic;">//            $MSG = &quot;Ha ocurrido un error al insertar los datos de la persona.\nPor favor, intentelo nuevamente.&quot;;</span>
<span style="color: #666666; font-style: italic;">//        }</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAlert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Str_SQL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$flag</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//		$conn-&gt;EjecutarSQL(&quot;COMMIT TRANSACTION A1&quot;);</span>
		<span style="color: #000088;">$MSG</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Datos guardados con exito&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAlert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$MSG</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$respuesta</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p class="MsoNormal"><span lang="ES-CL">Si bien puede que no sea la mejor forma de realizarlo pero es lo mejor que se me ocurrió y lo más importante es que funciona.</span></p>
<p class="MsoNormal"><span lang="ES-CL"> </span></p>
<p class="MsoNormal"><span lang="ES-CL">Espero que les sirva.</span></p>
<p class="MsoNormal"><span lang="ES-CL">Disfrútenlo y cualquier duda o comentario no teman en escribir.</span></p>
<p class="MsoNormal"><span lang="ES-CL"> </span></p>
<p class="MsoNormal"><span lang="ES-CL">Éxito.</span></p>
<p><br class="spacer_" /></p>
<p>Este ejemplo lo puedes ver en el siguiente enlace:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/ejecutar.png" width="48" height="48" alt="Ver Ejemplo" />
</td>
<td><a href="http://prodev.cl/tutoriales/agregarfilaxajaxyguardar.php" target="_blank">ejemplo funcionando de</a> Guardar en Base de Datos las Filas agregadas con xajax y PHP
   </td>
</tr>
</table>
<p>Tambien puedes decargar estos ejemplos:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/comp.png" width="48" height="48" alt="Ver Ejemplo" />
   </td>
<td><a href="http://prodev.cl/tutoriales/agregarfilaxajaxyguardar.zip" target="_blank">archivos de </a> Guardar en Base de Datos las Filas agregadas con xajax y PHP
   </td>
</tr>
<tr>
<td colspan="2"><b>Si te gust&oacute; o te sirvi&oacute;, ya sabes que hacer <img src='http://prodev.cl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </b></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://prodev.cl/2009/03/guardar-datos-en-base-de-datos-las-filas-agregadas-dinamicamente-con-xajax/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		<feedburner:origLink>http://prodev.cl/2009/03/guardar-datos-en-base-de-datos-las-filas-agregadas-dinamicamente-con-xajax/</feedburner:origLink></item>
		<item>
		<title>Como agregar filas o rows a una tabla dinamicamente mediante xajax</title>
		<link>http://feedproxy.google.com/~r/Prodev/~3/CC7USS5O-ms/</link>
		<comments>http://prodev.cl/2009/01/como-agregar-filas-rows-tabla-dinamicamente-mediante-xajax/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 23:11:43 +0000</pubDate>
		<dc:creator>eALL</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[xajax]]></category>
		<category><![CDATA[dinamico]]></category>

		<guid isPermaLink="false">http://prodev.cl/?p=104</guid>
		<description><![CDATA[Xajax se ha vuelto parte de mi trabajo a lo largo de este ya casi año de vida laboral, por lo que mi experiencia, aunque poca, ha ido evolucionando poco a poco. Si me hubieran preguntado como hacer para añadir una fila a una tabla les habria dicho que no se podía o que mejor [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/tJggvriaZ_dhF-ZiAaQsxwB4ph0/0/da"><img src="http://feedads.g.doubleclick.net/~a/tJggvriaZ_dhF-ZiAaQsxwB4ph0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/tJggvriaZ_dhF-ZiAaQsxwB4ph0/1/da"><img src="http://feedads.g.doubleclick.net/~a/tJggvriaZ_dhF-ZiAaQsxwB4ph0/1/di" border="0" ismap="true"></img></a></p><p>Xajax se ha vuelto parte de mi trabajo a lo largo de este ya casi año de vida laboral, por lo que mi experiencia, aunque poca, ha ido evolucionando poco a poco. Si me hubieran preguntado como hacer para añadir una fila a una tabla les habria dicho que no se podía o que mejor agregaran una tabla completa mediante el comando addAssign. Hoy, con un poco más de experiencia, les mostraré como podemos agregar el número de filas y campos que queramos a una tabla.<br />
El proceso es simple, iremos creando las etiquetas o tags HTML según su jerarquía y le iremos añadiendo dentro el contenido que corresponda. Para esto utilizaremos los comandos <span style="font-weight: bold;">addCreate</span> que crea nuevas etiquetas HTML, y <span style="font-weight: bold;">addAssign</span> que como ya deberían saber, agrega o inserta en el atributo indicado el valor que le pasemos por parametro. Primero crearemos el tag <span style="font-weight: bold;">tr</span> y luego cada uno de los tags <span style="font-weight: bold;">td</span> que necesitemos, para así, en ultima instancia, asignar el contenido de cada campo.</p>
<p>Veamos como quedaría nuestra función PHP agregaFila()</p>
<p><span id="more-104"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> agregarFila<span style="color: #009900;">&#40;</span><span style="color: #000088;">$formulario</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$respuesta</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xajaxResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$formulario</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$id_campos</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cant_campos</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$num_campos</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$str_html_td1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$txtNombre</span>&quot;</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$txtEdad</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$txtDireccion</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td4</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$selSexo</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td5</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$selEstCivil</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$str_html_td6</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;images/delete.png&quot; width=&quot;16&quot; height=&quot;16&quot; alt=&quot;Eliminar&quot; onclick=&quot;if(confirm(\'Realmente desea eliminar este detalle?\')){xajax_eliminarFila('</span><span style="color: #339933;">.</span> <span style="color: #000088;">$id_campos</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">', proyecto.cant_campos.value);}&quot;/&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num_campos</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// creamos un encabezado de lo contrario solo agragamos la fila</span>
		<span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tbDetalle&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tr&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;rowDetalle_0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rowDetalle_0&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;th&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tdDetalle_01&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">//creamos los campos</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rowDetalle_0&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;th&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tdDetalle_02&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rowDetalle_0&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;th&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tdDetalle_03&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rowDetalle_0&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;th&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tdDetalle_04&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rowDetalle_0&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;th&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tdDetalle_05&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rowDetalle_0&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;th&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tdDetalle_06&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tdDetalle_01&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Nombre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">//asignamos el contenido</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tdDetalle_02&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Edad&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tdDetalle_03&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Direccion&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tdDetalle_04&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Sexo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tdDetalle_05&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Estado Civil&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tdDetalle_06&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Eliminar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$idRow</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;rowDetalle_<span style="color: #006699; font-weight: bold;">$id_campos</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$idTd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;tdDetalle_<span style="color: #006699; font-weight: bold;">$id_campos</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tbDetalle&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tr&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$idRow</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idRow</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;td&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">//creamos los campos</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idRow</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;td&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idRow</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;td&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idRow</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;td&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;4&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idRow</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;td&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;5&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCreate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idRow</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;td&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;6&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
 *     Esta parte podria estar dentro de algun ciclo iterativo  */</span>
&nbsp;
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str_html_td1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">//asignamos el contenido</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str_html_td2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str_html_td3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;4&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str_html_td4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;5&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str_html_td5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idTd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;6&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str_html_td6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*  aumentamos el contador de campos  */</span>
&nbsp;
	<span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;num_campos&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id_campos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cant_campos&quot;</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id_campos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$respuesta</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
El HTML para esta aplicacion:</p>
</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;proyecto&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;proyecto&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;num_campos&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;num_campos&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cant_campos&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cant_campos&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cont&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>El formulario<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;label&quot;</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtNombre&quot;</span>&gt;</span>Nombre:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtNombre&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtNombre&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;label&quot;</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtEdad&quot;</span>&gt;</span>Edad:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtEdad&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtEdad&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox txtUser&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;label&quot;</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtDireccion&quot;</span>&gt;</span>Direccion:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtDireccion&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtDireccion&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox txtCmt&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;label&quot;</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selSexo&quot;</span>&gt;</span>Sexo:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selSexo&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selSexo&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox txtFec&quot;</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-&quot;</span>&gt;</span>Seleccione<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Hombre&quot;</span>&gt;</span>Hombre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Mujer&quot;</span>&gt;</span>Mujer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;label&quot;</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selEstCivil&quot;</span>&gt;</span>Estado Civil:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selEstCivil&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selEstCivil&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox txtFec&quot;</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-&quot;</span>&gt;</span>Seleccione<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Soltero&quot;</span>&gt;</span>Soltero<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Casado&quot;</span>&gt;</span>Casado<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Viudo&quot;</span>&gt;</span>Viudo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button_div&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;reset&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;btnCancel&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;btnCancel&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Cancelar&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;buttons_CANCEL&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;xajax_cancelar();&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;btnAgregar&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;btnAgregar&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Agregar Persona&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;buttons_aplicar&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;xajax_agregarFila(xajax.getFormValues('proyecto'));&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fieldset&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">legend</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;legend&quot;</span>&gt;</span>
        Detalle de Personas
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clear&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;form3&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;form-horiz&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tblDetalle&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;listado&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tbody</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tbDetalle&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>Y como sabroso entremes, le traemos&#8230; la función que elimina las filas agregadas por la función anterior.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> eliminarFila<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id_campo</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cant_campos</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$respuesta</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xajaxResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRemove</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rowDetalle_<span style="color: #006699; font-weight: bold;">$id_campo</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//borro el detalle que indica el parametro id_campo</span>
	<span style="color: #339933;">--</span> <span style="color: #000088;">$cant_campos</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Resto uno al numero de campos y si es cero borro todo</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cant_campos</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRemove</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rowDetalle_0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;num_campos&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//dejo en cero la cantidad de campos para seguir agregando si asi lo desea el usuario</span>
		<span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cant_campos&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cant_campos&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cant_campos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$respuesta</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As&iacute; de facil y bonito es agregar filas a las tablas dinamicamente usando xajax&#8230; las opciones son muchas y las dejo a su imaginaci&oacute;n o necesidad&#8230;<br />
Espero les sirva y cualquier duda o comentario responderé a la brevedad.<br />
Adios.</p>
<p>Este ejemplo lo puedes ver en el siguiente enlace:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/ejecutar.png" width="48" height="48" alt="Ver Ejemplo" />
</td>
<td><a href="http://prodev.cl/tutoriales/agregarfilaxajax.php" target="_blank">ejemplo funcionando de</a> Agregar Filas con xajax y PHP
   </td>
</tr>
</table>
<p>Tambien puedes decargar estos ejemplos:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/comp.png" width="48" height="48" alt="Ver Ejemplo" />
   </td>
<td><a href="http://prodev.cl/tutoriales/agregarfilaxajax.zip" target="_blank">archivos de</a> Agregar Filas con xajax y PHP
   </td>
</tr>
<tr>
<td colspan="2"><b>Si te gust&oacute; o te sirvi&oacute;, ya sabes que hacer <img src='http://prodev.cl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </b></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://prodev.cl/2009/01/como-agregar-filas-rows-tabla-dinamicamente-mediante-xajax/feed/</wfw:commentRss>
		<slash:comments>56</slash:comments>
		<feedburner:origLink>http://prodev.cl/2009/01/como-agregar-filas-rows-tabla-dinamicamente-mediante-xajax/</feedburner:origLink></item>
		<item>
		<title>Como crear combo box o select dinámico con jQuery</title>
		<link>http://feedproxy.google.com/~r/Prodev/~3/9KlvOL53AKk/</link>
		<comments>http://prodev.cl/2008/11/como-crear-combo-box-o-select-dinamico-con-jquery/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 19:20:37 +0000</pubDate>
		<dc:creator>eALL</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[dependientes]]></category>
		<category><![CDATA[dinamico]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://prodev.cl/?p=94</guid>
		<description><![CDATA[jQuery en una librería javascript que nos permite hacer cosas muy interesantes de manera muy secilla. Además tiene un repositorio de plugins con muchas cosas ya escritas que solo hace falta utilizarlas.
Al igual que en el tutorial Como crear combo box dinámico con xajax  la idea aquí es la misma, con la diferencia que [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/pa4OJBC9mmp-b61SGTpc146DWpc/0/da"><img src="http://feedads.g.doubleclick.net/~a/pa4OJBC9mmp-b61SGTpc146DWpc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/pa4OJBC9mmp-b61SGTpc146DWpc/1/da"><img src="http://feedads.g.doubleclick.net/~a/pa4OJBC9mmp-b61SGTpc146DWpc/1/di" border="0" ismap="true"></img></a></p><p><a href="http://jquery.com" target="_blank">jQuery</a> en una librería javascript que nos permite hacer cosas muy interesantes de manera muy secilla. Además tiene un repositorio de <a href="http://plugins.jquery.com/" target="_blank">plugins</a> con muchas cosas ya escritas que solo hace falta utilizarlas.</p>
<p class="topTitle">Al igual que en el tutorial <a href="http://prodev.cl/2008/10/como-crear-combo-box-dinamico-con-xajax/">Como crear combo box dinámico con xajax </a> la idea aquí es la misma, con la diferencia que podemos hacerlo con otro lenguaje que no sea PHP como por ejemplo ASP o <del datetime="2009-06-26T17:18:00+00:00">CGI</del> utilizar otros como C a través de CGI. Se trata de generar el codigo HTML del select e insertarlo en un DIV preestablecido al generar un evento en nuestro código.</p>
<p class="topTitle">A diferencia de xajax, en el cual llamabamos a una función específica dentro de nuestro código PHP, aquí se llama a un archivo completo, por lo que debemos crear un mecanismo para diferenciar a que función queremos que se acceda cada vez que se llame dinámicamente nuestro archivo. esto puede hacerse a través de condiciones &#8220;IF&#8221; o &#8220;switch &#8211; case&#8221;.</p>
<p><span id="more-94"></span></p>
<p class="topTitle">Primero debemos descargar la librería desde su <a href="http://docs.jquery.com/Downloading_jQuery">página de descarga</a> e incluirla en nuestro archivo HTML al igual que cualquier librería javascript.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/jquery.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p class="topTitle">luego generamos nuestro primer select (el estático) que filtrará los resultados de nuestro segundo select (el dinámico) dentro de un DIV con un id específico.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;divSelMeses&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selMeses&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selMeses&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>-Mes-<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>Enero<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>Febrero<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span>&gt;</span>Marzo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span>&gt;</span>Abril<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span>&gt;</span>Mayo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;6&quot;</span>&gt;</span>Junio<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;7&quot;</span>&gt;</span>Juilo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span>&gt;</span>Agosto<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;9&quot;</span>&gt;</span>Septiembre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span>&gt;</span>Octubre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;11&quot;</span>&gt;</span>Novienbre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;12&quot;</span>&gt;</span>Diciembre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
 <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;divSelDias&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selDias&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox&quot;</span> <span style="color: #000066;">onChange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>-Día-<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
 <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Hecho esto, crearemos nuestro script PHP (o el lenguaje que ustedes deseen) que genere nuestro select dinamico.<br />
Como dije al principio se debe crear una condición para saber a que parte del código dirigirnos si es que queremos utilizar nuestro archivo en más de una ocación con más de una función dentro. Esto lo haremos recibiendo, en este caso, variables mediante el metodo POST.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> obtieneDias<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mes</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//indicamos el nuevo valor que este tendrá. Cadena HTML</span>
<span style="color: #666666; font-style: italic;">//obtengo el ultimo día del mes para generar las opciones del selector.</span>
 <span style="color: #000088;">$ultimoDiaMes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t m&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mes</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
&lt;select name='selDias' class='textbox' onChange=''&gt;&lt;option value='0'&gt;-Día-&lt;/option&gt;&quot;</span><span style="color: #339933;">;</span>
 <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;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$ultimoDiaMes</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;">$valorAAsignar</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;option value='<span style="color: #006699; font-weight: bold;">$i</span>'&gt; <span style="color: #006699; font-weight: bold;">$i</span> &lt;/option&gt;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/select&gt;
&nbsp;
&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$valorAAsignar</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//se 'imprime' el HTML para que sea tomado por la funcion load</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Lo siguiente es crear nuestra función javascript basada en jQuery. Para ello utilizaremos la función <a href="http://docs.jquery.com/Ajax/load#urldatacallback" target="_blank">load</a> que nos permite llamar a un archivo mandando parametros mediante el método POST. la función increiblemente secilla es esta:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
 $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//así es como se crean las funciones jQuery. solo cree</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#selMeses&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//se ejecuta con el evento onChange</span>
   <span style="color: #003366; font-weight: bold;">var</span> varMes <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  <span style="color: #006600; font-style: italic;">//Devuelve el valor del campo, en este caso el select estatico</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#divSelDias&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;generaHTML.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>paramTipo <span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> paramMes <span style="color: #339933;">:</span> varMes<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//paramTipo es el parametro pasado por metodo POST</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//change</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//ready</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Esta pequeña función nos sirve para incluir cualquier elemento HTML dentro de nuestra página dinamicamente.</p>
<p>Este ejemplo lo puedes ver en el siguiente enlace:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/ejecutar.png" width="48" height="48" alt="Ver Ejemplo" />
</td>
<td><a href="http://prodev.cl/tutoriales/comboDinamicojq.php" target="_blank">ejemplo funcionando de</a> select dependientes con jQuery
   </td>
</tr>
</table>
<p>Tambien puedes decargar estos ejemplos:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/comp.png" width="48" height="48" alt="Ver Ejemplo" />
   </td>
<td><a href="http://prodev.cl/tutoriales/comboDinamicojq.zip" target="_blank">archivos de</a> select dependientes con jQuery
   </td>
</tr>
<tr>
<td colspan="2"><b>Si te gust&oacute; o te sirvi&oacute;, ya sabes que hacer <img src='http://prodev.cl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </b></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://prodev.cl/2008/11/como-crear-combo-box-o-select-dinamico-con-jquery/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://prodev.cl/2008/11/como-crear-combo-box-o-select-dinamico-con-jquery/</feedburner:origLink></item>
		<item>
		<title>Como crear combo box o select dinámico con xajax parte II</title>
		<link>http://feedproxy.google.com/~r/Prodev/~3/ebMKj9xTs18/</link>
		<comments>http://prodev.cl/2008/11/como-crear-combo-box-o-select-dinamico-con-xajax-parte-ii/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 18:56:41 +0000</pubDate>
		<dc:creator>eALL</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[xajax]]></category>
		<category><![CDATA[actualizar]]></category>
		<category><![CDATA[combobox]]></category>
		<category><![CDATA[dependientes]]></category>
		<category><![CDATA[dinamico]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://prodev.cl/?p=76</guid>
		<description><![CDATA[En la primera parte de este tutorial de Como crear combo box dinámico con xajax mostré como crear los combobox o select dinamicos dependientes. Ahora, que pasa si yo quiero hacer un select dinamico dependiente de otro select, que a su vez, es dependiente de otro select, o sea select dependientes com más de un [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/LTBCBQWgMRklK1Nz00l-9PSdzWA/0/da"><img src="http://feedads.g.doubleclick.net/~a/LTBCBQWgMRklK1Nz00l-9PSdzWA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/LTBCBQWgMRklK1Nz00l-9PSdzWA/1/da"><img src="http://feedads.g.doubleclick.net/~a/LTBCBQWgMRklK1Nz00l-9PSdzWA/1/di" border="0" ismap="true"></img></a></p><p>En la primera parte de este tutorial de <a href="http://prodev.cl/2008/10/como-crear-combo-box-dinamico-con-xajax/" target="_blank">Como crear combo box dinámico con xajax</a> mostré como crear los combobox o select dinamicos dependientes. Ahora, que pasa si yo quiero hacer un select dinamico dependiente de otro select, que a su vez, es dependiente de otro select, o sea select dependientes com más de un nivel.</p>
<p><span id="more-76"></span></p>
<p>La logica es sencilla. Lo primero que hay que hacer es conservar la estructura del <a href="http://prodev.cl/2008/10/como-crear-combo-box-dinamico-con-xajax/" target="_blank">ejemplo anterior</a> y añadir un nuevo select que filtre los resultados del segundo. Yo elegí que el primer select fueran las estaciones del año, ya saben, verano, invierno, otroño y promavera.<br />
 Pues bien, como cada estación del año abarca practicamente 3 meses cada una (sin tomar en cuenta los ultimos dias cuando cambia la estación), por lo tanto, cada vez que seleccionemos una estación, mi select mostrará los meses con los que se compone la estación seleccionada (Primer nivel de dependencia). Luego, al seleccionar alguno se los meses filtrados, se llenará el tercer combo con los dias que ese mes tiene (Segundo nivel de dependencia).</p>
<p>Para logar que cada select rellene el siguiente select, debemos crear una funcion xajax para cada uno e indicarle al selecet que cuando selecciones una opción (onChange) llame a nuestra función.</p>
<p>Los select quedar&iacute;an as&iacute;:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selMeses&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox&quot;</span> <span style="color: #000066;">onChange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;xajax_obtieneMeses(this.value)&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>-Estación-<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>Verano<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>Otoño<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span>&gt;</span>Invierno<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span>&gt;</span>Primavera<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> obtieneMeses<span style="color: #009900;">&#40;</span><span style="color: #000088;">$estacion</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$respuesta</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xajaxResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Creamos el objeto xajax</span>
  <span style="color: #000088;">$inputDestino</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;divSelMes&quot;</span><span style="color: #339933;">;</span>			<span style="color: #666666; font-style: italic;">//indicamos el ID del tag HTML de destino. en este caso el DIV que contiene el selector</span>
  <span style="color: #000088;">$propiedadInputDestino</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//indicamos la propiedad que deseamos que se modifique. Colocaremos el selector dentro del DIV</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>				<span style="color: #666666; font-style: italic;">//indicamos el nuevo valor que este tendrá. Cadena HTML</span>
  <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$estacion</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//genero el array de meses dependiendo de la estación seleccionda</span>
    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
      <span style="color: #000088;">$array_estacion</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Enero&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Febrero&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Marzo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
      <span style="color: #000088;">$array_estacion</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Abril&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Mayo&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Junio&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span>
      <span style="color: #000088;">$array_estacion</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Julio&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Agosto&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Septiembre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">:</span>
      <span style="color: #000088;">$array_estacion</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Octubre&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Noviembre&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Diciembre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
&lt;select name='selMes' class='textbox' onChange='xajax_obtieneDias(this.value)'&gt;&lt;option value='0'&gt;-Mes-&lt;/option&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$estacion</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//parto desde la estación seleccionada</span>
  <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array_estacion</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$est</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;option value='<span style="color: #006699; font-weight: bold;">$i</span>'&gt; <span style="color: #006699; font-weight: bold;">$est</span> &lt;/option&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/select&gt;
&nbsp;
&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$inputDestino</span><span style="color: #339933;">,</span> <span style="color: #000088;">$propiedadInputDestino</span><span style="color: #339933;">,</span> <span style="color: #000088;">$valorAAsignar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$respuesta</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Otra cosa interesante que podemos desear hacer es un select dinamico que dependa de otros 2 select no anidados, o sea, que sean independientes el uno del otro.<br />
 En este caso, lo que debemos hacer es llamar a la funcion que genera el select desde los otros 2 select de los cuales depende el primero, verificando, eso si, que ambos select tienen datos, ya que si falta algun dato puede que nos devuelva información errornea, en el mejor de los casos, o que nuestro programa se caiga.</p>
<p>El codigo es el que sigue:</p>
<p>El HTML</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selAno&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox&quot;</span> <span style="color: #000066;">onChange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript: if(document.proyecto.selMeses.value != 0){xajax_obtieneDias(document.proyecto.selMeses.value, this.value);}&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>-Año-<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;?</span>
<span style="color: #009900;">  <span style="color: #000066;">for</span><span style="color: #66cc66;">&#40;</span>$i <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1990</span>; $i &lt;<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">2010</span>; $i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></span>
<span style="color: #009900;">?&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;? echo $i ?&gt;</span></span>&quot;&gt;<span style="color: #009900;">&lt;? echo $i ?&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;?</span>
<span style="color: #009900;">  <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #009900;">?&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selMeses&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox&quot;</span> <span style="color: #000066;">onChange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript: if(document.proyecto.selAno.value == 0){alert('Debe seleccionar el año.');}else{xajax_obtieneDias(this.value, document.proyecto.selAno.value);}&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>-Mes-<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>Enero<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>Febrero<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span>&gt;</span>Marzo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span>&gt;</span>Abril<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span>&gt;</span>Mayo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;6&quot;</span>&gt;</span>Junio<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;7&quot;</span>&gt;</span>Juilo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span>&gt;</span>Agosto<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;9&quot;</span>&gt;</span>Septiembre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span>&gt;</span>Octubre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;11&quot;</span>&gt;</span>Novienbre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;12&quot;</span>&gt;</span>Diciembre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span></pre></div></div>

<p>El PHP</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> obtieneDias<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ano</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$respuesta</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xajaxResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Creamos el objeto xajax</span>
  <span style="color: #000088;">$inputDestino</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;divSelDias&quot;</span><span style="color: #339933;">;</span>			<span style="color: #666666; font-style: italic;">//indicamos el ID del tag HTML de destino. en este caso el DIV que contiene el selector</span>
  <span style="color: #000088;">$propiedadInputDestino</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//indicamos la propiedad que deseamos que se modifique. Colocaremos el selector dentro del DIV</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>				<span style="color: #666666; font-style: italic;">//indicamos el nuevo valor que este tendrá. Cadena HTML</span>
  <span style="color: #666666; font-style: italic;">//obtengo el ultimo día del mes para generar las opciones del selector.</span>
  <span style="color: #000088;">$ultimoDiaMes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mes</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ano</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
&lt;select name='selDias' class='textbox' onChange=''&gt;&lt;option value='0'&gt;-Día-&lt;/option&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mes</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <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;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$ultimoDiaMes</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;">$valorAAsignar</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;option value='<span style="color: #006699; font-weight: bold;">$i</span>'&gt; <span style="color: #006699; font-weight: bold;">$nomDia</span> &lt;/option&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$nomDia</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D, d&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ano</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/select&gt;
&nbsp;
&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$inputDestino</span><span style="color: #339933;">,</span> <span style="color: #000088;">$propiedadInputDestino</span><span style="color: #339933;">,</span> <span style="color: #000088;">$valorAAsignar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$respuesta</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ambos ejemplos los puedes ver en los siguientes enlace:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/ejecutar.png" width="48" height="48" alt="Ver Ejemplo" />
   </td>
<td><a href="http://prodev.cl/tutoriales/comboDinamico2.php" target="_blank">ejemplo funcionando de</a> select dependiente de select relacionados (1° caso)<br />
 <a href="http://prodev.cl/tutoriales/comboDinamico3.php" target="_blank">ejemplo funcionando de</a>select dependiente de select relacionados (2° caso)
   </td>
</tr>
</table>
<p>Tambien puedes decargar estos ejemplos:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/comp.png" width="48" height="48" alt="Ver Ejemplo" />
   </td>
<td><a href="http://prodev.cl/tutoriales/comboDinamico2.zip" target="_blank">archivos de</a> select dependiente de select relacionados (1° caso)<br />
 <a href="http://prodev.cl/tutoriales/comboDinamico3.php" target="_blank">archivos de</a> select dependiente de select relacionados (2° caso)
   </td>
</tr>
<tr>
<td colspan="2"><b>Si te gust&oacute; o te sirvi&oacute;, ya sabes que hacer <img src='http://prodev.cl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </b></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://prodev.cl/2008/11/como-crear-combo-box-o-select-dinamico-con-xajax-parte-ii/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://prodev.cl/2008/11/como-crear-combo-box-o-select-dinamico-con-xajax-parte-ii/</feedburner:origLink></item>
		<item>
		<title>Como agregar imagen de precarga con xajax</title>
		<link>http://feedproxy.google.com/~r/Prodev/~3/HsZjbQkvFjU/</link>
		<comments>http://prodev.cl/2008/11/como-agregar-imagen-de-precarga-con-xajax/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 17:19:27 +0000</pubDate>
		<dc:creator>eALL</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[xajax]]></category>
		<category><![CDATA[cargando]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[preload]]></category>

		<guid isPermaLink="false">http://prodev.cl/?p=69</guid>
		<description><![CDATA[Cada vez que generamos una llamada a una metodo xajax se genera un tiempo de espera que es inperceptible para el usuario, lo que muchas veces hace que este vuelva a generar acciones que pueden acabar en consecuencias desagradables para nosotos. Esto se puede evitar indicando al usuario que el sistema está &#8220;Trabajando&#8221; o está [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/fNG7yU70CQonzzuRg-t-e94bc7M/0/da"><img src="http://feedads.g.doubleclick.net/~a/fNG7yU70CQonzzuRg-t-e94bc7M/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/fNG7yU70CQonzzuRg-t-e94bc7M/1/da"><img src="http://feedads.g.doubleclick.net/~a/fNG7yU70CQonzzuRg-t-e94bc7M/1/di" border="0" ismap="true"></img></a></p><p>Cada vez que generamos una llamada a una metodo xajax se genera un tiempo de espera que es inperceptible para el usuario, lo que muchas veces hace que este vuelva a generar acciones que pueden acabar en consecuencias desagradables para nosotos. Esto se puede evitar indicando al usuario que el sistema está &#8220;Trabajando&#8221; o está &#8220;Cargando&#8221;.<br />
El proceso es bastante sencillo, cuando xajax envia una petición llama a un metodo llamado &#8220;loadingFunction&#8221; y cuando se completa la carga llama al metodo &#8220;doneLoadingFunction&#8221; por lo que nosotros aprovecharemos estos eventos para generar nuestro mensaje &#8220;Cargando&#8230;&#8221;.<span id="more-69"></span>Para empesar debemos crear un div en nuestro código HTML en donde queremos que se muestre nuestro mensaje de carga y lo dejaremos invisible. Luego dentro del div, al cual obviamente le asignamos una ID, colocamos la tipica imagen de precarga que sea de nuestro agrado. Pueden obtener algunas desde <a title="Generador de Preloads" href="http://www.loadinfo.net/" target="_blank">http://www.loadinfo.net/</a> o <a title="Otro generador de preloads" href="http://www.ajaxload.info/" target="_blank">http://www.ajaxload.info/</a> .<br />
Nuestro div quedaría como este:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;loading&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;display:none&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;../images/load.gif&quot;</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;absmiddle&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Cargando...&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Luego le indicamos al metodo xajax que cuando se ejecute llame a una funcion nuestra, la cual hará visible u ocultará el div que contiene la imagen. las funciones quedarán como sigue:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;!--</span>
xajax.<span style="color: #660066;">loadingFunction</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>xajax.$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loading'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//creamos la función que se llamará cuando comience la carga.</span>
<span style="color: #003366; font-weight: bold;">function</span> hideLoadingMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//creamos la función que se ejecutará cuando acabe la carga.</span>
<span style="color: #009900;">&#123;</span>
  xajax.$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loading'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
xajax.<span style="color: #660066;">doneLoadingFunction</span> <span style="color: #339933;">=</span> hideLoadingMessage<span style="color: #339933;">;</span>
<span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

</p>
<p>Ahora es cosa de probar que tal quedó.</p>
<p>Los creditos no son para mi, solo que no recuerdo de donde lo saque. <img src='http://prodev.cl/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Este ejemplo lo puedes ver en el siguiente enlace:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/ejecutar.png" width="48" height="48" alt="Ver Ejemplo" />
</td>
<td><a href="http://prodev.cl/tutoriales/cargar_xajax.php" target="_blank">ejemplo funcionando de</a> Como agregar imagen de precarga con xajax
   </td>
</tr>
</table>
<p>Tambien puedes decargar estos ejemplos:</p>
<table>
<tr>
<td><img src="http://prodev.cl/images/comp.png" width="48" height="48" alt="Ver Ejemplo" />
   </td>
<td><a href="http://prodev.cl/tutoriales/cargarxajax.zip" target="_blank">archivos de </a> Como agregar imagen de precarga con xajax
   </td>
</tr>
<tr>
<td colspan="2"><b>Si te gust&oacute; o te sirvi&oacute;, ya sabes que hacer <img src='http://prodev.cl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </b></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://prodev.cl/2008/11/como-agregar-imagen-de-precarga-con-xajax/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://prodev.cl/2008/11/como-agregar-imagen-de-precarga-con-xajax/</feedburner:origLink></item>
		<item>
		<title>Como crear combo box dinámico con xajax</title>
		<link>http://feedproxy.google.com/~r/Prodev/~3/somyT2dH6o0/</link>
		<comments>http://prodev.cl/2008/10/como-crear-combo-box-dinamico-con-xajax/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 18:28:26 +0000</pubDate>
		<dc:creator>eALL</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[xajax]]></category>
		<category><![CDATA[actualizar]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[box]]></category>
		<category><![CDATA[combo]]></category>
		<category><![CDATA[combobox]]></category>
		<category><![CDATA[dependientes]]></category>
		<category><![CDATA[dinamico]]></category>

		<guid isPermaLink="false">http://prodev.cl/?p=48</guid>
		<description><![CDATA[Una de las tareas típicas de un programador es crear comos dinámicos o dependientes. Para esta tarea habia que nesesariamente recargar la pagina. Gracias a la tecnología Ajax eso es parte de la historia.
 En este articulo esplicaré como hacerlo mediante la libreria xajax.
 Básicamente lo que haremos será llamar a nuestra función PHP mediante [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/s8rFrSjgN9Z_nKsnya6f3Ps01bA/0/da"><img src="http://feedads.g.doubleclick.net/~a/s8rFrSjgN9Z_nKsnya6f3Ps01bA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/s8rFrSjgN9Z_nKsnya6f3Ps01bA/1/da"><img src="http://feedads.g.doubleclick.net/~a/s8rFrSjgN9Z_nKsnya6f3Ps01bA/1/di" border="0" ismap="true"></img></a></p><p>Una de las tareas típicas de un programador es crear comos dinámicos o dependientes. Para esta tarea habia que nesesariamente recargar la pagina. Gracias a la tecnología Ajax eso es parte de la historia.<br />
 En este articulo esplicaré como hacerlo mediante la libreria <a title="Proyecto xaJax" href="http://xajaxproject.org" target="_blank">xajax</a>.<br />
 Básicamente lo que haremos será llamar a nuestra función PHP mediante xajax y generaremos el código HTML que incrustaremos en una etiqueta div.<span id="more-48"></span></p>
<p>Lo primero que debemos hacer es incluir todas las librerias necesaria y crear las instrucciones que harán que xajax funciones correctamente. (encabezados)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'xajax/xajax.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//incluimos la librelia xajax</span>
<span style="color: #666666; font-style: italic;">/*
     Funciones PHP
*/</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> xajax<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Crea un nuevo objeto xajax</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCharEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;iso-8859-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// le indica la codificación que debe utilizar</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">decodeUTF8InputOn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// decodifica los caracteres extraños</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerFunction</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;obtieneDias&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Registramos la función para indicar que se utilizará con xajax.</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">processRequests</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>En el selector debemos llamar a la función xajax en el evento onChange y pasamos por parametro el numero del mes seleccinado. Además debemos crear un DIV en el cual recepcionar el selector creado dinamicamente. (selector)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtDia&quot;</span>&gt;</span>Meses<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;divdia&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selMeses&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox&quot;</span> <span style="color: #000066;">onChange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;xajax_obtieneDias()&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>-Mes-<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>Enero<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>Febrero<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span>&gt;</span>Marzo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span>&gt;</span>Abril<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span>&gt;</span>Mayo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;6&quot;</span>&gt;</span>Junio<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;7&quot;</span>&gt;</span>Juilo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span>&gt;</span>Agosto<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;9&quot;</span>&gt;</span>Septiembre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span>&gt;</span>Octubre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;11&quot;</span>&gt;</span>Novienbre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;12&quot;</span>&gt;</span>Diciembre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtDia&quot;</span>&gt;</span>Dias<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;divSelDias&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;menu1&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox&quot;</span> <span style="color: #000066;">onChange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>-Día-<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Ahora creamos la función php que generará los numeros del mes seleccionado y crea un nuevo selector que será insertado en el DIV creado anteriormente. (Funcion PHP)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> obtieneDias<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mes</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$respuesta</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xajaxResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Creamos el objeto xajax</span>
  <span style="color: #000088;">$inputDestino</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;divSelDias&quot;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">//indicamos el ID del tag HTML de destino. en este caso el DIV que contiene el selector</span>
  <span style="color: #000088;">$propiedadInputDestino</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">//indicamos la propiedad que deseamos que se modifique. Colocaremos el selector dentro del DIV</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">//indicamos el nuevo valor que este tendrá. Cadena HTML</span>
  <span style="color: #666666; font-style: italic;">//obtengo el ultimo día del mes para generar las opciones del selector.</span>
  <span style="color: #000088;">$ultimoDiaMes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mes</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
&lt;select name='selDias' class='textbox' onChange=''&gt;
    &lt;option value='0'&gt;-Día-&lt;/option&gt; &quot;</span><span style="color: #339933;">;</span>
  <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;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$ultimoDiaMes</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;">$valorAAsignar</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;option value='<span style="color: #006699; font-weight: bold;">$i</span>'&gt; <span style="color: #006699; font-weight: bold;">$i</span> &lt;/option&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/select&gt;
&nbsp;
&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$inputDestino</span><span style="color: #339933;">,</span> <span style="color: #000088;">$propiedadInputDestino</span><span style="color: #339933;">,</span> <span style="color: #000088;">$valorAAsignar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$respuesta</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ahora cada vez que se seleccione un mes, muestra función php generará el selector con el número de días que corresponda.<br />
El ejemplo completo lo vemos a continuación:</p>
<p>PHP</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'xajax/xajax.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//incluimos la librelia xajax</span>
<span style="color: #000000; font-weight: bold;">function</span> obtieneDias<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mes</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$respuesta</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xajaxResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Creamos el objeto xajax</span>
  <span style="color: #000088;">$inputDestino</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;divSelDias&quot;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//indicamos el ID del tag HTML de destino. en este caso el DIV que contiene el selector</span>
  <span style="color: #000088;">$propiedadInputDestino</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;innerHTML&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//indicamos la propiedad que deseamos que se modifique. Colocaremos el selector dentro del DIV</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">//indicamos el nuevo valor que este tendrá. Cadena HTML</span>
  <span style="color: #666666; font-style: italic;">//obtengo el ultimo día del mes para generar las opciones del selector.</span>
  <span style="color: #000088;">$ultimoDiaMes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mes</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
&lt;select name='selDias' class='textbox' onChange=''&gt;
      &lt;option value='0'&gt;-Día-&lt;/option&gt;&quot;</span><span style="color: #339933;">;</span>
  <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;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$ultimoDiaMes</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;">$valorAAsignar</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;option value='<span style="color: #006699; font-weight: bold;">$i</span>'&gt; <span style="color: #006699; font-weight: bold;">$i</span> &lt;/option&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$valorAAsignar</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/select&gt;
&nbsp;
&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$respuesta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAssign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$inputDestino</span><span style="color: #339933;">,</span> <span style="color: #000088;">$propiedadInputDestino</span><span style="color: #339933;">,</span> <span style="color: #000088;">$valorAAsignar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$respuesta</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> xajax<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// Crea un nuevo objeto xajax</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCharEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;iso-8859-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// le indica la codificación que debe utilizar</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">decodeUTF8InputOn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// decodifica los caracteres extraños</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerFunction</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;obtieneDias&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Registramos la función para indicar que se utilizará con xajax.</span>
<span style="color: #000088;">$xajax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">processRequests</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>HTML</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Pragma&quot;</span><span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;no-cache&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;expires&quot;</span><span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;?php $xajax-&gt;</span>printJavascript(&quot;xajax&quot;); //imprime el codigo javascript necesario para que funcione todo.?&gt;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;CSS/style.css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;proyecto&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;proyecto&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cont&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>El formulario<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtDia&quot;</span>&gt;</span>Meses<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;divdia&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;selMeses&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox&quot;</span> <span style="color: #000066;">onChange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;xajax_obtieneDias(this.value)&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>-Mes-<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>Enero<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>Febrero<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span>&gt;</span>Marzo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span>&gt;</span>Abril<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span>&gt;</span>Mayo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;6&quot;</span>&gt;</span>Junio<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;7&quot;</span>&gt;</span>Juilo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span>&gt;</span>Agosto<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;9&quot;</span>&gt;</span>Septiembre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span>&gt;</span>Octubre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;11&quot;</span>&gt;</span>Novienbre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;12&quot;</span>&gt;</span>Diciembre<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtDia&quot;</span>&gt;</span>Dias<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div_texbox&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;divSelDias&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;menu1&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textbox&quot;</span> <span style="color: #000066;">onChange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>-Día-<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Puedes ver un <a href="http://prodev.cl/tutoriales/comboDinamico.php">ejemplo funcionando aqu&iacute;</a><br />
Puedes descargar <a href="http://prodev.cl/tutoriales/comboDinamico.zip">este ejemplo aqu&iacute;</a></p>
<p><b>Si te gust&oacute; o te sirvi&oacute;, ya sabes que hacer <img src='http://prodev.cl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </b></p>
]]></content:encoded>
			<wfw:commentRss>http://prodev.cl/2008/10/como-crear-combo-box-dinamico-con-xajax/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://prodev.cl/2008/10/como-crear-combo-box-dinamico-con-xajax/</feedburner:origLink></item>
	</channel>
</rss>
