<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>jQuery Archives - My Silly Point of View</title>
	<atom:link href="https://mysillypointofview.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>https://mysillypointofview.com</link>
	<description>it&#039;s my blog anyway</description>
	<lastBuildDate>Sat, 16 Apr 2011 03:31:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.9.13</generator>
<site xmlns="com-wordpress:feed-additions:1">13951596</site>	<item>
		<title>Auto-select all &#060;option&#062; items from multiple select dropdown using jQuery</title>
		<link>https://mysillypointofview.com/2011/04/12/auto-select-all-option-items-from-multiple-select-dropdown-using-jquery/</link>
					<comments>https://mysillypointofview.com/2011/04/12/auto-select-all-option-items-from-multiple-select-dropdown-using-jquery/#comments</comments>
		
		<dc:creator><![CDATA[Richard Feraro]]></dc:creator>
		<pubDate>Tue, 12 Apr 2011 00:00:00 +0000</pubDate>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[Techie Daw]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">http://mysillypointofview.richardferaro.com/2011/04/12/auto-select-all-option-items-from-multiple-select-dropdown-using-jquery/</guid>

					<description><![CDATA[<p>I’ve been working for the past few days with jQuery and one of the task was to manipulate HTML forms before submitting it for processing. What I needed to do is to process a form having multiple submit buttons and select tags. These set of select tags requires all values to be selected on submit. [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://mysillypointofview.com/2011/04/12/auto-select-all-option-items-from-multiple-select-dropdown-using-jquery/">Auto-select all &lt;option&gt; items from multiple select dropdown using jQuery</a> appeared first on <a rel="nofollow" href="https://mysillypointofview.com">My Silly Point of View</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I’ve been working for the past few days with jQuery and one of the task was to manipulate HTML forms before submitting it for processing. What I needed to do is to process a form having multiple submit buttons and select tags. These set of select tags requires all values to be selected on submit.</p>
<p><span id="more-717"></span></p>
<p>Let’s start with creating the markup of the form. Save the HTML below and name it as <code>index.htm</code> (we won’t be needing PHP stuff for now in this exercise.)</p>
<p><pre class="brush: xml; title: ; notranslate">&lt;!doctype html&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
&lt;title&gt;Sample Form&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
	&lt;form id=&quot;myForm&quot; action=&quot;index.html&quot; method=&quot;post&quot; onSubmit=&quot;return false;&quot;&gt;
		&lt;select id=&quot;do-not-select&quot; name=&quot;do-not-select[]&quot; multiple=&quot;multiple&quot; size=&quot;3&quot;&gt;
			&lt;option&gt;Do&lt;/option&gt;
			&lt;option&gt;not&lt;/option&gt;
			&lt;option&gt;select&lt;/option&gt;
		&lt;/select&gt;
		&lt;select id=&quot;color&quot; name=&quot;color[]&quot; multiple=&quot;multiple&quot; size=&quot;3&quot;&gt;
			&lt;option&gt;Red&lt;/option&gt;
			&lt;option&gt;Green&lt;/option&gt;
			&lt;option&gt;Blue&lt;/option&gt;
		&lt;/select&gt;
		&lt;select id=&quot;size&quot; name=&quot;size[]&quot; multiple=&quot;multiple&quot; size=&quot;3&quot;&gt;
			&lt;option&gt;Small&lt;/option&gt;
			&lt;option&gt;Medium&lt;/option&gt;
			&lt;option&gt;Large&lt;/option&gt;
		&lt;/select&gt;
		&lt;select id=&quot;category&quot; name=&quot;category[]&quot; multiple=&quot;multiple&quot; size=&quot;3&quot;&gt;
			&lt;option&gt;Children&lt;/option&gt;
			&lt;option&gt;Ladies&lt;/option&gt;
			&lt;option&gt;Men&lt;/option&gt;
		&lt;/select&gt;
		&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
	&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</p>
<p>The markup above will create a single form with an id of <strong>myForm</strong> having four (4) multi-select field with the following ids: </p>
<ul>
<li>do-not-select</li>
<li>color</li>
<li>size</li>
<li>category</li>
</ul>
<p>At line 6, we added the jQuery file (latest version 1.5.2 as of this writing) to use it&#8217;s functionality in manipulating <a href="http://en.wikipedia.org/wiki/Document_Object_Model">DOM objects</a>. Now for the real action, copy the code below and insert it between line 6 and 7:</p>
<p><pre class="brush: xml; title: ; notranslate">&lt;script&gt;
$(document).ready(function() {
	$('#myForm').submit(function() {
		$('#color, #size, #category').find('option').each(function() {
			$(this).attr('selected', 'selected');
		});
	});
});
&lt;/script&gt;</pre>
</p>
<p>The script above will do the following task: </p>
<ol type="1">
<li>Instruct the browser to execute the script within <code>$(document).ready(...);</code> when the page has loaded. </li>
<li>Trigger the script within <code>$('#myForm').submit(...)</code> once the form with an id of <strong>myForm</strong> is submitted. </li>
<li>With the given <code>SELECT</code> element ids (color, size, category), find all <code>OPTION</code> tags in each of them and add the attribute and value <code>selected=&quot;selected&quot;</code> </li>
</ol>
<p>We also added at line 10 the event handler <code>onSubmit</code> with <code>return false;</code> to prevent the page on submitting while we are testing the script.</p>
<p>That&#8217;s it! Load the file on your browser and click Submit button. It should highlight all the options under color, size and category while ignoring the <strong>do-not-select</strong> option since we didn&#8217;t add them in the affected elements. See the full markup below. Remember to remove the <code>onSubmit="return false;"</code> in the <code>FORM</code> tag to enable redirection of your form on submit.</p>
<p><pre class="brush: xml; title: ; notranslate">&lt;!doctype html&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
&lt;title&gt;Sample Form&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
$(document).ready(function() {
	$('#myForm').submit(function() {
		$('#color, #size, #category').find('option').each(function() {
			$(this).attr('selected', 'selected');
		});
	});
});
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
	&lt;form id=&quot;myForm&quot; action=&quot;index.html&quot; method=&quot;post&quot; onSubmit=&quot;return false;&quot;&gt;
		&lt;select id=&quot;do-not-select&quot; name=&quot;do-not-select[]&quot; multiple=&quot;multiple&quot; size=&quot;3&quot;&gt;
			&lt;option&gt;Do&lt;/option&gt;
			&lt;option&gt;not&lt;/option&gt;
			&lt;option&gt;select&lt;/option&gt;
		&lt;/select&gt;
		&lt;select id=&quot;color&quot; name=&quot;color[]&quot; multiple=&quot;multiple&quot; size=&quot;3&quot;&gt;
			&lt;option&gt;Red&lt;/option&gt;
			&lt;option&gt;Green&lt;/option&gt;
			&lt;option&gt;Blue&lt;/option&gt;
		&lt;/select&gt;
		&lt;select id=&quot;size&quot; name=&quot;size[]&quot; multiple=&quot;multiple&quot; size=&quot;3&quot;&gt;
			&lt;option&gt;Small&lt;/option&gt;
			&lt;option&gt;Medium&lt;/option&gt;
			&lt;option&gt;Large&lt;/option&gt;
		&lt;/select&gt;
		&lt;select id=&quot;category&quot; name=&quot;category[]&quot; multiple=&quot;multiple&quot; size=&quot;3&quot;&gt;
			&lt;option&gt;Children&lt;/option&gt;
			&lt;option&gt;Ladies&lt;/option&gt;
			&lt;option&gt;Men&lt;/option&gt;
		&lt;/select&gt;
		&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
	&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></p>
<p>The post <a rel="nofollow" href="https://mysillypointofview.com/2011/04/12/auto-select-all-option-items-from-multiple-select-dropdown-using-jquery/">Auto-select all &lt;option&gt; items from multiple select dropdown using jQuery</a> appeared first on <a rel="nofollow" href="https://mysillypointofview.com">My Silly Point of View</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mysillypointofview.com/2011/04/12/auto-select-all-option-items-from-multiple-select-dropdown-using-jquery/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">717</post-id>	</item>
	</channel>
</rss>
