{"id":391,"date":"2022-08-30T15:00:34","date_gmt":"2022-08-30T15:00:34","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/jquery-2-dropdowns-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:00:34","modified_gmt":"2022-08-30T15:00:34","slug":"jquery-2-dropdowns-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/jquery-2-dropdowns-collection-of-common-programming-errors\/","title":{"rendered":"jQuery &#8211; 2 dropdown&#39;s-Collection of common programming errors"},"content":{"rendered":"<p>Try this way:-<\/p>\n<h3>Demo<\/h3>\n<pre><code>var id = this.value;\/\/Get the value of the option.\nvar options = $(this).data('options'); \/\/get all the saved options.\n\nif (id) { \/\/if there is value then filter it out\n    options = $(this).data('options').filter('[value=' + id + ']');\n}\n$('#select2').html(options).prop('selectedIndex', 0); \/\/save option and set selectedindex to first element.\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-09 18:42:01. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Try this way:- Demo var id = this.value;\/\/Get the value of the option. var options = $(this).data(&#8216;options&#8217;); \/\/get all the saved options. if (id) { \/\/if there is value then filter it out options = $(this).data(&#8216;options&#8217;).filter(&#8216;[value=&#8217; + id + &#8216;]&#8217;); } $(&#8216;#select2&#8217;).html(options).prop(&#8216;selectedIndex&#8217;, 0); \/\/save option and set selectedindex to first element. Originally posted 2013-11-09 18:42:01.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-391","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=391"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/391\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}