{"id":624,"date":"2013-05-13T05:18:55","date_gmt":"2013-05-13T09:18:55","guid":{"rendered":"http:\/\/www.searchenginegenie.com\/programming-blog\/?p=624"},"modified":"2013-05-13T06:53:49","modified_gmt":"2013-05-13T10:53:49","slug":"how-to-use-jquery-mutliselect-dropdown","status":"publish","type":"post","link":"https:\/\/www.searchenginegenie.com\/programming-blog\/how-to-use-jquery-mutliselect-dropdown\/","title":{"rendered":"How To Use Jquery Mutliselect Dropdown"},"content":{"rendered":"<p><b style=\"font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px;\">I am using <\/b><span style=\"font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px;\">http:\/\/www.erichynds.com\/jquery\/jquery-ui-multiselect-widget\/<\/span><\/p>\n<p><b>\u00a0Samples here<\/b><\/p>\n<p>Initially it seemed tough to get it working as a beginner, but eventually I managed to successfully get it to work.<\/p>\n<p>Step 1:<\/p>\n<p>Download the Jquery Code Or You Can Include it From CDN (Content Delievery Network)<\/p>\n<p>For multiple select drop-down, We need to include the following resource,<\/p>\n<p>Download links are<\/p>\n<div id=\"resources\">\n<ol>\n<li><a title=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.10.2\/jquery-ui.min.js\" href=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.10.2\/jquery-ui.min.js\">jquery-ui.min.js<\/a><\/li>\n<li><a title=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.10.2\/themes\/ui-lightness\/jquery-ui.css\" href=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.10.2\/themes\/ui-lightness\/jquery-ui.css\">jquery-ui.css<\/a><\/li>\n<li><a title=\"https:\/\/raw.github.com\/ehynds\/jquery-ui-multiselect-widget\/master\/src\/jquery.multiselect.js\" href=\"https:\/\/raw.github.com\/ehynds\/jquery-ui-multiselect-widget\/master\/src\/jquery.multiselect.js\">jquery.multiselect.js<\/a><\/li>\n<li><a title=\"http:\/\/erichynds.com\/examples\/jquery-ui-multiselect-widget\/jquery.multiselect.css\" href=\"http:\/\/erichynds.com\/examples\/jquery-ui-multiselect-widget\/jquery.multiselect.css\">jquery.multiselect.css<\/a><\/li>\n<\/ol>\n<\/div>\n<p>After including the above files your code will look like:<\/p>\n<p>[php]<br \/>\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1\/themes\/ui-lightness\/jquery-ui.css&quot; \/&gt;<br \/>\n&lt;script type=&quot;text\/javascript&quot; src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1\/jquery.js&quot;&gt;<br \/>\n&lt;\/script&gt;<br \/>\n&lt;script type=&quot;text\/javascript&quot; src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1\/jquery-ui.min.js&quot;&gt;&lt;\/script&gt;<br \/>\n&lt;script type=&quot;text\/javascript&quot; src=&quot;..\/src\/jquery.multiselect.js&quot;&gt;&lt;\/script&gt;<br \/>\n[\/php]<\/p>\n<p>Step 2:<\/p>\n<p>Use JavaScript Function to Trigger Multi-Select Event<\/p>\n<p>[php]<br \/>\n&lt;script&gt;<br \/>\n $(document).ready(function(){<br \/>\n   $(&quot;#check_list&quot;).multiselect();<br \/>\n });<br \/>\n&lt;\/script&gt;<br \/>\n[\/php]<\/p>\n<p>For customizing multi-select,We have to pass in a object \u00a0with one or more options like header.height etc. For all available options <a title=\"http:\/\/www.erichynds.com\/blog\/jquery-ui-multiselect-widget\" href=\"http:\/\/www.erichynds.com\/blog\/jquery-ui-multiselect-widget\">Click Here<\/a><\/p>\n<p>Step 3:<\/p>\n<p>In &lt;select&gt; tag define multiple attribute for selecting multiple options and define name in array format as specified below.<\/p>\n<p>Note that at the end of check_list in the &lt;name&gt;tag <strong>[]<\/strong>\u00a0symbol<strong>\u00a0<\/strong>is used,that denotes the array<\/p>\n<p>[php]<br \/>\n&lt;select name=&quot;check_list[]&quot; id=&quot;check_list&quot; multiple=&quot;multiple&quot;&gt;<br \/>\n  &lt;option value=&quot;1&quot;&gt; Apple &lt;\/option&gt;<br \/>\n  &lt;option value=&quot;2&quot;&gt; Orange &lt;\/option&gt;<br \/>\n  &lt;option value=&quot;3&quot;&gt; Mango &lt;\/option&gt;<br \/>\n  &lt;option value=&quot;4&quot;&gt; Grapes &lt;\/option&gt;<br \/>\n  &lt;option value=&quot;5&quot;&gt; Strawberry &lt;\/option&gt;<br \/>\n&lt;\/select&gt;<br \/>\n[\/php]<\/p>\n<p>Step 4:<\/p>\n<p>When you have embedded this multi-select dropdown in your form,<\/p>\n<p>Output will be Displayed as<\/p>\n<p><a href=\"http:\/\/www.searchenginegenie.com\/programming-blog\/wp-content\/uploads\/2013\/05\/drop_down1.bmp\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-646\" alt=\"drop_down\" src=\"http:\/\/www.searchenginegenie.com\/programming-blog\/wp-content\/uploads\/2013\/05\/drop_down1.bmp\" \/><\/a><\/p>\n<p>Step 5:<\/p>\n<p>Onclicking submit button the value selected in drop-down is posted as an array.Let us assume we are using \u00a0PHP to get this value.<\/p>\n<p>[php]<br \/>\nif(!empty($_POST[&#8216;check_list&#8217;])){ \/\/Checking if check_list control is empty or not<br \/>\n  foreach($_POST[&#8216;check_list&#8217;] as $check){ \/\/Looping through the array of values in foreach<br \/>\n    print_r($check);\/\/return the value of the variable<br \/>\n    $test = implode(&#8216;,&#8217;,$check);\/\/ implode tha array value to pass it in a query<br \/>\n}<br \/>\n}<br \/>\n[\/php]<br \/>\nYour complete code will look like this<br \/>\n[html]<br \/>\n&lt;html lang=&quot;en&quot;&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=utf-8&quot; \/&gt;<br \/>\n&lt;title&gt;jQuery MultiSelect Dropdown&lt;\/title&gt;<br \/>\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;..\/jquery.multiselect.css&quot; \/&gt;<br \/>\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1\/themes\/ui-lightness\/jquery-ui.css&quot; \/&gt;<br \/>\n&lt;script type=&quot;text\/javascript&quot; src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1\/jquery.js&quot;&gt;<br \/>\n&lt;\/script&gt;<br \/>\n&lt;script type=&quot;text\/javascript&quot; src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1\/jquery-ui.min.js&quot;&gt;&lt;\/script&gt;<br \/>\n&lt;script type=&quot;text\/javascript&quot; src=&quot;..\/src\/jquery.multiselect.js&quot;&gt;&lt;\/script&gt;<br \/>\n&lt;script type=&quot;text\/javascript&quot;&gt;<br \/>\n\t $(document).ready(function(){<br \/>\n  \t\t $(&quot;#check_list&quot;).multiselect();<br \/>\n \t });<br \/>\n&lt;\/script&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body id=&quot;test&quot;&gt;<br \/>\n  &lt;form id=&quot;multiple&quot; method=&quot;post&quot; enctype=&quot;multipart\/form-data&quot;&gt;<br \/>\n\t &lt;select title=&quot;Basic example&quot; multiple=&quot;multiple&quot; name=&quot;example-basic&quot; size=&quot;5&quot;&gt;<br \/>\n\t   &lt;option value=&quot;1&quot;&gt;Apple&lt;\/option&gt;<br \/>\n\t   &lt;option value=&quot;2&quot;&gt;Orange&lt;\/option&gt;<br \/>\n\t   &lt;option value=&quot;3&quot;&gt;Mango&lt;\/option&gt;<br \/>\n\t   &lt;option value=&quot;4&quot;&gt;Grapes&lt;\/option&gt;<br \/>\n\t   &lt;option value=&quot;5&quot;&gt;Strawberry&lt;\/option&gt;<br \/>\n\t&lt;\/select&gt;<br \/>\n\t &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot; \/&gt;<br \/>\n  &lt;\/form&gt;<br \/>\n&lt;?php<br \/>\nif(isset($_POST[&#8216;submit&#8217;])){<br \/>\n\tif(!empty($_POST[&#8216;check_list&#8217;])){<br \/>\n\t  foreach($_POST[&#8216;check_list&#8217;] as $check){<br \/>\n\t\tprint_r($check);<br \/>\n\t\t$test = implode(&#8216;,&#8217;,$check);<br \/>\n\t}<br \/>\n\t}<br \/>\n$fruits = mysql_query(&quot;SELECT * FROM fruits WHERE fruit_id IN(&quot;.$test.&quot;)&quot;);<br \/>\n$fetch_fruits = mysql_fetch_array($fruits);<br \/>\n$name = $fetch_fruits[&#8216;fruit_name&#8217;];<br \/>\n$desc = $fetch_fruits[&#8216;desc&#8217;];<br \/>\necho &#8216;&lt;div&gt;&quot;&#8217;.$name.&#8217;&quot;&lt;\/div&gt;&#8217;;<br \/>\necho &#8216;&lt;div&gt;&quot;&#8217;.$desc.&#8217;&quot;&lt;\/div&gt;&#8217;;<br \/>\n}<br \/>\n?&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<br \/>\n[\/html]<\/p>\n<p>For working example of Multi-select dropdown checkbox<a href=\"http:\/\/www.virtualregenie.com\"> Click Here<\/a><\/p>\n<p><strong>Must know before reading this article<\/strong><\/p>\n<ul>\n<li>PHP Basics<\/li>\n<li>HTML Basics<\/li>\n<li>Jquery<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I am using http:\/\/www.erichynds.com\/jquery\/jquery-ui-multiselect-widget\/ \u00a0Samples here Initially it seemed tough to get it working as a beginner, but eventually I managed to successfully get it to work. Step 1: Download the Jquery Code Or You Can Include it From CDN (Content Delievery Network) For multiple select drop-down, We need to include the following resource, Download [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-624","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/comments?post=624"}],"version-history":[{"count":48,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/624\/revisions"}],"predecessor-version":[{"id":697,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/624\/revisions\/697"}],"wp:attachment":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/media?parent=624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/categories?post=624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/tags?post=624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}