<?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>markup &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/markup/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>jQuery: Get the Selected Option Text</title>
		<link>/2010/06/22/jquery-get-the-selected-option-text/</link>
		<comments>/2010/06/22/jquery-get-the-selected-option-text/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 17:33:56 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[Markup languages]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[Technical communication]]></category>

		<guid isPermaLink="false">/?p=1660</guid>
		<description><![CDATA[What&#8217;s the Task? First of all let me explain what is the task. If there&#8217;s a select menu with several options, each of which are with a given value attribute, the task is to get the text into the option tag, and not that of the value attribute. In that scenario let&#8217;s assume that we &#8230; <a href="/2010/06/22/jquery-get-the-selected-option-text/" class="more-link">Continue reading <span class="screen-reader-text">jQuery: Get the Selected Option Text</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/09/27/jquery-setting-up-a-vector-path-fill-color/" rel="bookmark" title="jQuery: Setting Up a Vector Path Fill Color">jQuery: Setting Up a Vector Path Fill Color </a></li>
<li><a href="/2011/04/05/jquery-unbind/" rel="bookmark" title="jQuery.unbind()">jQuery.unbind() </a></li>
<li><a href="/2010/02/16/jquery-tooltip-plugin/" rel="bookmark" title="jQuery tooltip plugin!">jQuery tooltip plugin! </a></li>
<li><a href="/2010/04/06/jquery-what-about-this-title/" rel="bookmark" title="jQuery: what about this.title?">jQuery: what about this.title? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>What&#8217;s the Task?</h2>
<p>First of all let me explain what is the task. If there&#8217;s a select menu with several options, each of which are with a given value attribute, the task is to get the text into the option tag, and not that of the value attribute.</p>
<p>In that scenario let&#8217;s assume that we have the following HTML:</p>
<pre lang="html4strict">
<select id="my-select">
    <option value="1">value 1</option>
    <option value="2">value 2</option>
</select>
</pre>
<p><a href="/wp-content/uploads/2010/06/Picture-1.png"><img src="/wp-content/uploads/2010/06/Picture-1.png" alt="select menu" title="Select Menu" width="181" height="95" class="alignleft size-full wp-image-1671" /></a><br />
Note that in the official jQuery doc page, the selector is described in the same context, but with a different markup:</p>
<pre lang="html4strict">
<select id="my-select">
    <option>value 1</option>
    <option>value 2</option>
</select>
</pre>
<p>than the jQuery snippet looks like that:</p>
<pre lang="javascript">
$(document).ready(function() {
    $("#my-select").change(function() {
        alert($(this).val());
    });
});
</pre>
<p>Here&#8217;s interesting to note that there&#8217;s no value attribute set to the options, thus the selection of an element is correct and the returned value is correct. The problem is that this code doesn&#8217;t work correctly once you&#8217;ve a different value attribute, from the value enclosed into the option tag. In our case we&#8217;ve the markup shown on the first code snippet and we&#8217;d like to get the &#8220;value 2&#8221; string instead of &#8220;2&#8221;.<br />
<a href="/wp-content/uploads/2010/06/Picture-2.png"><img src="/wp-content/uploads/2010/06/Picture-2.png" alt="" title="Alert screen" width="329" height="130" class="alignleft size-full wp-image-1672" srcset="/wp-content/uploads/2010/06/Picture-2.png 329w, /wp-content/uploads/2010/06/Picture-2-300x118.png 300w" sizes="(max-width: 329px) 100vw, 329px" /></a></p>
<h2>Source Code</h2>
<pre lang="html4strict">
<select id="my-select">
    <option value="1">value 1</option>
    <option value="2">value 2</option>
</select>
</pre>
<pre lang="javascript">
$(document).ready(function() {
    $("#my-select").change(function() {
        alert($(this).val());
    });
});
</pre>
<h2>Solution</h2>
<p>Finally the solution, is pretty simple and clear, but this time is not to so &#8220;native&#8221; and it&#8217;s definitely something you couldn&#8217;t expect! The only thing you&#8217;ve to do is to change the selector!</p>
<pre lang="javascript">
$(document).ready(function() {
    $("#my-select).change(function() {
        alert($('#my-select option:selected').html());
    });
});
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/09/27/jquery-setting-up-a-vector-path-fill-color/" rel="bookmark" title="jQuery: Setting Up a Vector Path Fill Color">jQuery: Setting Up a Vector Path Fill Color </a></li>
<li><a href="/2011/04/05/jquery-unbind/" rel="bookmark" title="jQuery.unbind()">jQuery.unbind() </a></li>
<li><a href="/2010/02/16/jquery-tooltip-plugin/" rel="bookmark" title="jQuery tooltip plugin!">jQuery tooltip plugin! </a></li>
<li><a href="/2010/04/06/jquery-what-about-this-title/" rel="bookmark" title="jQuery: what about this.title?">jQuery: what about this.title? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/22/jquery-get-the-selected-option-text/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
