﻿<?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>Actualidad jQuery &#187; Select</title>
	<atom:link href="http://www.actualidadjquery.es/category/formularios/select-formularios/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.actualidadjquery.es</link>
	<description>Blog de actualidad acerca de jQuery con tutoriales y ejemplos</description>
	<lastBuildDate>Tue, 24 Jan 2012 11:10:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Comprobar el valor de un campo select y modificarlo en jQuery</title>
		<link>https://www.actualidadjquery.es/2010/10/27/comprobar-el-valor-de-un-campo-select-y-modificarlo-en-jquery/</link>
		<comments>https://www.actualidadjquery.es/2010/10/27/comprobar-el-valor-de-un-campo-select-y-modificarlo-en-jquery/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 06:24:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Formularios]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[click]]></category>
		<category><![CDATA[formularios]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[selected]]></category>

		<guid isPermaLink="false">http://www.actualidadjquery.es/?p=168</guid>
		<description><![CDATA[Ayer os explicabamos como trabajar con los campos checkbox, validar su estado y cambiar su estado mediante jQuery. Hoy vamos a hacer lo mismo pero con un campo select. Hemos creado 4 botones, 1 bot&#243;n para comprobar el estado del select, y los otros 3 botones para cambiar la opci&#243;n seleccionada. Primero vamos a obtener [...]]]></description>
			<content:encoded><![CDATA[<p><img align="left" alt="" height="121" src="http://www.actualidadjquery.es/wp-content/uploads/image/jquery_logo_color_onwhite.jpg" width="490" />Ayer os explicabamos como trabajar con los campos checkbox, validar su estado y cambiar su estado mediante jQuery. Hoy vamos a hacer lo mismo pero con un campo select.</p>
<p>	Hemos creado 4 botones, 1 bot&oacute;n para comprobar el estado del select, y los otros 3 botones para cambiar la opci&oacute;n seleccionada.</p>
<p>	Primero vamos a obtener la opci&oacute;n seleccionada del select, el id y el texto, presionando sobre el bot&oacute;n.</p>
<pre class="javascript" name="code">$(document).ready(function(){

	$(&quot;#select_comprobar&quot;).click(function() {
		alert(&quot;Id: &quot;+$(&quot;#sexo option:selected&quot;).val()+&quot; | Texto: &quot;+$(&quot;#sexo option:selected&quot;).text());
	});

});</pre>
<p>Una vez que presionemos el bot&oacute;n recibiremos en un alert el id y el texto de la opci&oacute;n seleccionada, gracias al atributo&nbsp;<strong>option:selected</strong> (<strong>$(&quot;#sexo option:selected&quot;).val()</strong> /&nbsp;<strong>$(&quot;#sexo option:selected&quot;).text()</strong>)</p>
<p>	Para terminar vamos a cambiar la opci&oacute;n seleccionada del select con estos 3 botones:</p>
<pre class="javascript" name="code">$(document).ready(function(){

	$(&quot;#select_cambiar_defecto&quot;).click(function() {
		$(&quot;#sexo option[value=0]&quot;).attr(&quot;selected&quot;,true);
	});

	$(&quot;#select_cambiar_hombre&quot;).click(function() {
		$(&quot;#sexo option[value=1]&quot;).attr(&quot;selected&quot;,true);
	});

	$(&quot;#select_cambiar_mujer&quot;).click(function() {
		$(&quot;#sexo option[value=2]&quot;).attr(&quot;selected&quot;,true);
	});

});</pre>
<p>El c&oacute;digo HTML quedar&iacute;a as&iacute;:</p>
<pre class="html" name="code">&lt;select name=&quot;sexo&quot; id=&quot;sexo&quot;&gt;
&lt;option value=&quot;0&quot;&gt;- Seleccionar -&lt;/option&gt;
&lt;option value=&quot;1&quot;&gt;Hombre&lt;/option&gt;
&lt;option value=&quot;2&quot;&gt;Mujer&lt;/option&gt;
&lt;/select&gt;

&lt;input name=&quot;select_comprobar&quot; id=&quot;select_comprobar&quot; type=&quot;button&quot; value=&quot;Comprobar&quot; /&gt;
&lt;input name=&quot;select_cambiar_defecto&quot; id=&quot;select_cambiar_defecto&quot; type=&quot;button&quot; value=&quot;Seleccionar defecto&quot; /&gt;
&lt;input name=&quot;select_cambiar_hombre&quot; id=&quot;select_cambiar_hombre&quot; type=&quot;button&quot; value=&quot;Seleccionar hombre&quot; /&gt;
&lt;input name=&quot;select_cambiar_mujer&quot; id=&quot;select_cambiar_mujer&quot; type=&quot;button&quot; value=&quot;Seleccionar mujer&quot; /&gt;</pre>
<ul>
<li><a href="http://www.actualidadjquery.es/ejemplos/13/index.html" target="_blank">Ejemplo</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://www.actualidadjquery.es/2010/10/27/comprobar-el-valor-de-un-campo-select-y-modificarlo-en-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
