{"id":90,"date":"2018-09-23T17:53:23","date_gmt":"2018-09-23T20:53:23","guid":{"rendered":"http:\/\/fabiobrandao.net.br\/blog\/?p=90"},"modified":"2023-03-12T00:19:17","modified_gmt":"2023-03-12T03:19:17","slug":"jquery-obter-valor-do-dropdown","status":"publish","type":"post","link":"https:\/\/fabiobrandao.net.br\/blog\/javascript-e-bivliotecas\/jquery-obter-valor-do-dropdown\/","title":{"rendered":"jQuery &#8211; Obter valor do Dropdown"},"content":{"rendered":"<p>Obter valor do Dropdown usando jQuery<\/p>\n<p>Em um outro post descrevi como voc\u00ea pode <a href=\"http:\/\/fabiobrandao.net.br\/blog\/jquery\/preencher-dropdown-com-json-usando-jquery\/\">preencher um dropdown com Json<\/a>. Claro que voc\u00ea tamb\u00e9m vai precisar saber qual valor foi selecionado neste dropdown. Isso \u00e9 bem simples de implementar.<\/p>\n<p>Considere que voc\u00ea tenha um dropdown com uma rela\u00e7\u00e3o de cidades onde o valor selecionado ser\u00e1 o id da cidade. O C\u00f3digo HTML poderia ser:<\/p>\n<p><code>&lt;select id=\"city\"&gt;&lt;\/select&gt;<br \/>\n<\/code><\/p>\n<p>Agora voc\u00ea precisa capturar o evento de sele\u00e7\u00e3o deste dropdown e em seguida, obter o valor selecionado.<\/p>\n<pre>$('#city').change(function () {\r\n   var id = $(this).val();\r\n   console.log(id);\r\n});\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Simples e r\u00e1pido!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Obter valor do Dropdown usando jQuery Em um outro post descrevi como voc\u00ea pode preencher um dropdown com Json. Claro que voc\u00ea tamb\u00e9m vai precisar saber qual valor foi selecionado&#8230; <\/p>\n","protected":false},"author":1,"featured_media":377,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[69],"tags":[16,9],"class_list":["post-90","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript-e-bivliotecas","tag-dropdown","tag-jquery"],"_links":{"self":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":8,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts\/90\/revisions"}],"predecessor-version":[{"id":383,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts\/90\/revisions\/383"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/media\/377"}],"wp:attachment":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/media?parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/categories?post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/tags?post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}