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

<channel>
	<title>Vivir y Aprender Web &#187; Jquery</title>
	<atom:link href="https://viviryaprenderweb.com/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>https://viviryaprenderweb.com</link>
	<description>Desarrollo web, recursos y tutoriales sobre xhtml, css, javascript, jquery, php, ruby on rails, seo y diseño web</description>
	<lastBuildDate>Wed, 20 Apr 2016 06:22:22 +0000</lastBuildDate>
	<language>es-ES</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>Validar campos de un formulario con Javascript</title>
		<link>https://viviryaprenderweb.com/validar-campos-de-un-formulario-con-javascript/</link>
		<comments>https://viviryaprenderweb.com/validar-campos-de-un-formulario-con-javascript/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 06:49:31 +0000</pubDate>
		<dc:creator><![CDATA[Ramón Torres]]></dc:creator>
				<category><![CDATA[Jquery]]></category>

		<guid isPermaLink="false">http://viviryaprenderweb.com/?p=36</guid>
		<description><![CDATA[<p>¿Cómo hacerlo? Ejemplo 1 Validar que los campos del formulario (unicamente los campos obligatorios) no se encuentren vacíos antes de enviarlo, de lo contrario el formulario no se enviará. Para este ejemplo he realizado la maquetación usando una tabla. Deseo ver de que se trata (explicación del ejemplo) Para presentar el formulario se ha usado [&#8230;]</p>
<p>La entrada <a rel="nofollow" href="https://viviryaprenderweb.com/validar-campos-de-un-formulario-con-javascript/">Validar campos de un formulario con Javascript</a> aparece primero en <a rel="nofollow" href="https://viviryaprenderweb.com">Vivir y Aprender Web</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h3>¿Cómo hacerlo?</h3>
<h4>Ejemplo 1</h4>
<p>Validar que los campos del formulario (unicamente los campos obligatorios) no se encuentren vacíos antes de enviarlo, de lo contrario el formulario no se enviará. Para este ejemplo he realizado la maquetación <strong>usando una tabla</strong>.</p>
<p><span id="more-36"></span></p>
<p><a class="more">Deseo ver de que se trata (explicación del ejemplo)</a></p>
<div class="detail">
<ul>
<li>Para presentar el formulario se ha usado una tabla.</li>
<li>El formulario cuenta con campos que son obligatorios (precedidos por un astericos)</li>
<li>Mientras los campos obligatorios no se ingresen, el formulario no será enviado.</li>
<li>Si se trata de enviar el formulario, los campos obligatorios serán marcados con un fondo rosado y un borde rojo, mas una legenda que indica que el campo es obligatorio.</li>
</ul>
</div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.6.4.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery.validator.js&quot;&gt;&lt;/script&gt;
<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: #000066; 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: #009900;">&#40;</span><span style="color: #3366CC;">'#register-form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">jValidator</span><span style="color: #009900;">&#40;</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></td></tr></table></div>

<h4>Ejemplo 2</h4>
<p>Validar que los campos del formulario (unicamente los campos obligatorios) no se encuentren vacíos antes de enviarlo, de lo contrario el formulario no se enviará. Para este ejemplo he realizado la maquetación <strong>usando párrafos</strong>.</p>
<p><a class="more">Deseo ver de que se trata (explicación del ejemplo)</a></p>
<div class="detail">
<ul>
<li>Para presentar el formulario se ha usado parrafos.</li>
<li>El formulario cuenta con campos que son obligatorios (precedidos por un astericos)</li>
<li>Mientras los campos obligatorios no se ingresen, el formulario no será enviado.</li>
<li>Si se trata de enviar el formulario, los campos obligatorios serán marcados con un fondo rosado y un borde rojo, mas una legenda que indica que el campo es obligatorio.</li>
</ul>
</div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.6.4.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery.validator.js&quot;&gt;&lt;/script&gt;
<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: #000066; 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: #009900;">&#40;</span><span style="color: #3366CC;">'#login-form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">jValidator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      tag<span style="color: #339933;">:</span> <span style="color: #3366CC;">'p'</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></td></tr></table></div>

<h3>Explicación</h3>
<p><a class="more">Deseo saber cómo funciona</a></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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;ruta/al/archivo/jquery.validator.css&quot; type=&quot;text/css&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;ruta/al/archivo/jquery&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;ruta/al/archivo/jquery.validator.js&quot;&gt;&lt;/script&gt;
<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: #006600; font-style: italic;">// Es importantísimo que una vez hayamos incluido la librería de jQuery, incluyamos el</span>
  <span style="color: #006600; font-style: italic;">// archivo jquery.validator.js, no antes. Asimismo, debemos de asegurarnos de incluir el</span>
  <span style="color: #006600; font-style: italic;">// archivo que contiene los estilos de error (jquery.validator.css); los estilos aquí definidos</span>
  <span style="color: #006600; font-style: italic;">// pueden ser modificados a antojo.</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: #000066; 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;">// Seleccionamos el formulario (en este caso por su 'id') y le asociamos el validador.</span>
    <span style="color: #006600; font-style: italic;">// Por defecto, se asume que se esta usando una tabla a fin de mostrar el formulario.</span>
    <span style="color: #006600; font-style: italic;">// Para mayor información acerca de los parámetros que puede recibir y sus respectivos</span>
    <span style="color: #006600; font-style: italic;">// valores por defectos, se ha dispuesto de una tabla con la información de estos valores.</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#register-form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">jValidator</span><span style="color: #009900;">&#40;</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></td></tr></table></div>

<table>
<tbody>
<tr>
<th>Parámetro</th>
<th>Valor por defecto</th>
<th>Descripción</th>
</tr>
<tr>
<td><code>wrapper</code></td>
<td>&#8216;jValidator&#8217;</td>
<td>La clase del <code>div</code> que contiene los elementos del formulario. Esta contenido dentro la etiqueta <code>&lt;form&gt;</code>.</td>
</tr>
<tr>
<td><code>tag</code></td>
<td>&#8216;tr&#8217;</td>
<td>Acepta como posibles valores: &#8216;tr&#8217; o &#8216;p&#8217;. Indica si elemento del formulario se encuentra dentro de un <code>&lt;p&gt;</code> o un <code>&lt;tr&gt;</code>.</td>
</tr>
<tr>
<td><code>error</code></td>
<td>&#8216;Campo obligatorio&#8217;</td>
<td>La leyenda a desplegará en caso el campo se encuentre vacío</td>
</tr>
</tbody>
</table>
<p>Para mayor información y saber cual es la estructura a respetar (estructura que se espera), descargar cualquiera de los ejemplos que se han colocado al inicio de este post.</p>
<h3>¿Necesitas otro ejemplo?</h3>
<p>Si necesitas otro ejemplo (uno más real), puedes dejar un comentario indicando tu solicitud, acerca de lo que quisieras que elaboraramos, y con gusto contestaremos tu solicitud.</p>
<h3>Próximo tema</h3>
<p><strong>Tabs (pestañas) con jQuery</strong></p>
<p>La entrada <a rel="nofollow" href="https://viviryaprenderweb.com/validar-campos-de-un-formulario-con-javascript/">Validar campos de un formulario con Javascript</a> aparece primero en <a rel="nofollow" href="https://viviryaprenderweb.com">Vivir y Aprender Web</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://viviryaprenderweb.com/validar-campos-de-un-formulario-con-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Texto &#8216;Buscar&#8217; por defecto</title>
		<link>https://viviryaprenderweb.com/texto-buscar-por-defecto/</link>
		<comments>https://viviryaprenderweb.com/texto-buscar-por-defecto/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 05:12:56 +0000</pubDate>
		<dc:creator><![CDATA[douglas.velasquez]]></dc:creator>
				<category><![CDATA[Jquery]]></category>

		<guid isPermaLink="false">http://viviryaprenderweb.com/?p=76</guid>
		<description><![CDATA[<p>¿Cómo hacerlo? Ejemplo 1 Colocamos un texto por defecto en la casilla de texto del buscador. Al cargar la página se coloca un texto por defecto (atributo «default») en la casilla de texto si esta se encuentra vacía. Al hacer clic en la casilla de texto, se quita el texto por defecto. Cuando se deja [&#8230;]</p>
<p>La entrada <a rel="nofollow" href="https://viviryaprenderweb.com/texto-buscar-por-defecto/">Texto &#8216;Buscar&#8217; por defecto</a> aparece primero en <a rel="nofollow" href="https://viviryaprenderweb.com">Vivir y Aprender Web</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h3>¿Cómo hacerlo?</h3>
<h4>Ejemplo 1</h4>
<p>Colocamos un texto por defecto en la casilla de texto del buscador.</p>
<p>Al cargar la página se coloca un texto por defecto (atributo «default») en la casilla de texto si esta se encuentra vacía.</p>
<p><span id="more-76"></span></p>
<div class="detail">
<ul>
<li>Al hacer clic en la casilla de texto, se quita el texto por defecto.</li>
<li>Cuando se deja la casilla de texto (eveto «blur»), se verifica el valor (atributo «value») de esta y si no se introdujo texto alguno se coloca el texto por defecto (atributo «default»).</li>
</ul>
</div>

<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
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.6.4.js&quot;&gt;&lt;/script&gt;
<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: #000066; 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: #000066; font-weight: bold;">function</span> init_input_search<span style="color: #009900;">&#40;</span>input_id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      input <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input#'</span><span style="color: #339933;">+</span>input_id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>input.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        default_text <span style="color: #339933;">=</span> input.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'default'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>default_text <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          default_text <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>default_text <span style="color: #339933;">!=</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> input.<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: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          input.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>default_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      input.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</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: #339933;">==</span> default_text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</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: #3366CC;">''</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      input.<span style="color: #660066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</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: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</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>default_text<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: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      input.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><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: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000066; 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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</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: #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;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'default'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</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: #3366CC;">''</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: #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>
&nbsp;
    init_input_search<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'search_by'</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></td></tr></table></div>

<h3>Explicación</h3>
<p><a class="more">Deseo saber cómo funciona</a></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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;ruta/al/archivo/jquery&quot;&gt;&lt;/script&gt;
<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: #000066; 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: #000066; font-weight: bold;">function</span> init_input_search<span style="color: #009900;">&#40;</span>input_id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      input <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input#'</span><span style="color: #339933;">+</span>input_id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// verificamos si la casilla de texto con el 'id' indicado existe</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>input.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// obtenemos el valor del atributo'default'</span>
        default_text <span style="color: #339933;">=</span> input.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'default'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>default_text <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          default_text <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #006600; font-style: italic;">// evaluamos que se haya definido un texto por defecto para mostrar en caso</span>
        <span style="color: #006600; font-style: italic;">// que la casilla de texto este en blanco; si es asi lo colocamos como valor de</span>
        <span style="color: #006600; font-style: italic;">// la casilla de texto</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>default_text <span style="color: #339933;">!=</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> input.<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: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          input.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>default_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">// si se hace clic en la casilla de texto, se quita el texto por  defecto colocado al</span>
      <span style="color: #006600; font-style: italic;">// cargar la página</span>
      input.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</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: #339933;">==</span> default_text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</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: #3366CC;">''</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">// cuando la casilla de texto se deja, colocamos el texto por defecto solo en caso</span>
      <span style="color: #006600; font-style: italic;">// que esta haya sido dejada en blanco</span>
      input.<span style="color: #660066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>default_text <span style="color: #339933;">!=</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<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: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</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>default_text<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: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">// antes de enviar el formulario limpiamos la casilla de texto si al enviar el formuario</span>
      <span style="color: #006600; font-style: italic;">// contiene el texto por defecto</span>
      input.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><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: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000066; 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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</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: #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;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'default'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</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: #3366CC;">''</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: #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>
&nbsp;
    <span style="color: #006600; font-style: italic;">// inicializamos la casilla de texto</span>
    init_input_search<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'search_by'</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></td></tr></table></div>

<h3>¿Necesitas otro ejemplo?</h3>
<p>Si necesitas otro ejemplo (uno más real), puedes dejar un comentario indicando tu solicitud, acerca de lo que quisieras que elaboraramos, y con gusto contestaremos tu solicitud.</p>
<p>La entrada <a rel="nofollow" href="https://viviryaprenderweb.com/texto-buscar-por-defecto/">Texto &#8216;Buscar&#8217; por defecto</a> aparece primero en <a rel="nofollow" href="https://viviryaprenderweb.com">Vivir y Aprender Web</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://viviryaprenderweb.com/texto-buscar-por-defecto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax con jQuery &#8211; básico</title>
		<link>https://viviryaprenderweb.com/ajax-con-jquery-basico/</link>
		<comments>https://viviryaprenderweb.com/ajax-con-jquery-basico/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 05:05:11 +0000</pubDate>
		<dc:creator><![CDATA[Ramón Torres]]></dc:creator>
				<category><![CDATA[Jquery]]></category>

		<guid isPermaLink="false">http://viviryaprenderweb.com/?p=7</guid>
		<description><![CDATA[<p>¿Cómo hacerlo? Ejemplo 1 Cargamos la lista de departamentos a partir del país seleccionado (evento «change» del control). Antes de enviar la petición colocamos una imagen &#8216;loading&#8217; con el texto alternativo «Cargando departamentos&#8230;» (esto último en caso que no se encuentre la imagen). Si el archivo a llamar no se encuentra mostramos una alerta con [&#8230;]</p>
<p>La entrada <a rel="nofollow" href="https://viviryaprenderweb.com/ajax-con-jquery-basico/">Ajax con jQuery &#8211; básico</a> aparece primero en <a rel="nofollow" href="https://viviryaprenderweb.com">Vivir y Aprender Web</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h3>¿Cómo hacerlo?</h3>
<h4>Ejemplo 1</h4>
<p>Cargamos la lista de departamentos a partir del país seleccionado (evento «change» del control).</p>
<div class="detail">
<ul>
<li>Antes de enviar la petición colocamos una imagen &#8216;loading&#8217; con el texto alternativo «Cargando departamentos&#8230;» (esto último en caso que no se encuentre la imagen).</li>
<li>Si el archivo a llamar no se encuentra mostramos una alerta con el texto «Ocurrio un problema al listar los departamentos del país seleccionado&#8230;».</li>
<li>Finalizada la petición ajax asignamos la salida obtenida al elemento con el <code>id</code> «states-cnt» (si se encontrarón departamentos, serán desplegados, sino será mostrado el texto «No hay departamentos configurados para este país»; esto es realizado por el archivo «find_states_by_country.php», el cual fue definido en el parámetro «url» del objeto <code>$.ajax</code>)</li>
</ul>
<p><span id="more-7"></span></p>
</div>

<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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.6.4.js&quot;&gt;&lt;/script&gt;
<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: #000066; 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: #009900;">&#40;</span><span style="color: #3366CC;">'#countries'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">var</span> country_id <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: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>country_id <span style="color: #339933;">!=</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">var</span> request_find_states <span style="color: #339933;">=</span>
          $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'GET'</span><span style="color: #339933;">,</span>
            url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;find_states_by_country.php&quot;</span><span style="color: #339933;">,</span>
            data<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>country_id<span style="color: #339933;">:</span> country_id<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            beforeSend<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xhr<span style="color: #339933;">,</span> settings<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
              $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#states-cnt&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;img src=&quot;</span>loading.<span style="color: #660066;">gif</span><span style="color: #3366CC;">&quot; alt=&quot;</span>Cargando departamentos...<span style="color: #3366CC;">&quot; /&gt;&quot;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            success<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #339933;">,</span> xhr<span style="color: #339933;">,</span> status<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
              $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#states-cnt&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            error<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xhr<span style="color: #339933;">,</span> status<span style="color: #339933;">,</span> exception<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
              alert<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Ocurrio un problema al listar los departamentos del pais seleccionado...&quot;</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</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></td></tr></table></div>

<h3>Explicación</h3>
<p><a class="more">Deseo saber cómo funciona</a></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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;ruta/al/archivo/jquery&quot;&gt;&lt;/script&gt;
<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: #000066; 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: #000066; font-weight: bold;">var</span> request <span style="color: #339933;">=</span>
      $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// tambien puede ser POST</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;ruta/al/archivo/a/llamar/via/ajax&quot;</span><span style="color: #339933;">,</span>
        data<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>parametro_1<span style="color: #339933;">:</span> valor_1<span style="color: #339933;">,</span> parametro_2<span style="color: #339933;">:</span> valor_2<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        beforeSend<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xhr<span style="color: #339933;">,</span> settings<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #006600; font-style: italic;">// acciones antes de realizar la petición vía ajax por ejemplo,</span>
          <span style="color: #006600; font-style: italic;">// podemos colocar un texto &quot;Cargando...&quot; para indicar al usuario que</span>
          <span style="color: #006600; font-style: italic;">// se esta esperando cierta respuesta y ocultar  el botón que realiza</span>
          <span style="color: #006600; font-style: italic;">// la peticion</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        success<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #339933;">,</span> xhr<span style="color: #339933;">,</span> status<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #006600; font-style: italic;">// acciones a realizar una vez se haya realizado la petición</span>
          <span style="color: #006600; font-style: italic;">// generalmente, procesar/mostrar la salida del archivo invocado</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        error<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xhr<span style="color: #339933;">,</span> status<span style="color: #339933;">,</span> exception<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #006600; font-style: italic;">// acciones a realizar en caso que no se encuentre el archivo a llamar</span>
        <span style="color: #009900;">&#125;</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></td></tr></table></div>

<h3>¿Necesitas otro ejemplo?</h3>
<p>Si necesitas otro ejemplo (uno más real), puedes dejar un comentario indicando tu solicitud, acerca de lo que quisieras que elaboraramos, y con gusto contestaremos tu solicitud.</p>
<p>La entrada <a rel="nofollow" href="https://viviryaprenderweb.com/ajax-con-jquery-basico/">Ajax con jQuery &#8211; básico</a> aparece primero en <a rel="nofollow" href="https://viviryaprenderweb.com">Vivir y Aprender Web</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://viviryaprenderweb.com/ajax-con-jquery-basico/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
