{"id":653,"date":"2012-05-29T09:43:59","date_gmt":"2012-05-29T09:43:59","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=653"},"modified":"2012-05-29T09:43:59","modified_gmt":"2012-05-29T09:43:59","slug":"jquery-add-options-to-select-from-array","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-add-options-to-select-from-array\/","title":{"rendered":"jQuery Add Options To Select from Array"},"content":{"rendered":"<p><strong>jQuery Add Options To Select from Array<\/strong> will help you add options dynamically to select dropdown from a pre-determined array. Read on to find out more about this simple solution.<!--more--><\/p>\n<h2>Example to Add Options To Select from Array using jQuery<\/h2>\n<p>Let&#8217;s assume that you have already created an array called &#8220;dropdown_values&#8221; that you want to add to a select dropdown with ID &#8220;my_states&#8221;. This select dropdwon already consists of some values.<\/p>\n<p><strong>Complete jQuery Code:<\/strong><\/p>\n<pre class=\"lang:xhtml decode:true\">\/\/Declare your array first in key: value format\ndropdown_values = {\"1\":\"Dallas\",\"2\":\"Texas\",\"3\":\"Philly\"};\n\n\/\/Then for each of the values of the array, append those values into the existing select \"my_states\" dropdown\n$.each(dropdown_values, function(key, value) {\n$('#my_states')\n.append($('&lt;option&gt;', { value : key })\n.text(value));\n});<\/pre>\n<p>So here&#8217;s how you can\u00a0add options to select dropdown from array using jQuery.<\/p>\n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to use\u00a0<strong><em>jQuery to Add Options To Select from Array<\/em><\/strong>? Feel free to share by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>jQuery Add Options To Select from Array will help you add options dynamically to select dropdown from a pre-determined array. Read on to find out more about this simple solution.<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[41],"class_list":["post-653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-ax","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=653"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/653\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}