{"id":210,"date":"2020-02-28T17:08:54","date_gmt":"2020-02-28T17:08:54","guid":{"rendered":"https:\/\/www.369usa.com\/blog\/?p=210"},"modified":"2020-02-28T17:10:04","modified_gmt":"2020-02-28T17:10:04","slug":"use-jquery-to-dynamically-update-days-field-when-year-month-changes","status":"publish","type":"post","link":"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/","title":{"rendered":"Use JQuery to dynamically update day&#8217;s field when year\/month changes"},"content":{"rendered":"<p>JQuery Code:<\/p>\n<pre>\r\n\r\n\/\/Adjust date picker days in month.\r\n$('select[name=birth_year],select[name=birth_month]').change(function(){\r\n    \r\n    var year = $('select[name=birth_year]').val();\r\n    var month = $('select[name=birth_month]').val();\r\n\r\n    var days_in_month = 31;\r\n\r\n    if( month == 2 &amp;&amp; year % 4 == 0 ){\r\n        days_in_month = 29;\r\n    }\r\n    else if( month == 2 &amp;&amp; year % 4 != 0 ){\r\n        days_in_month = 28;\r\n    }\r\n    else if( $.inArray(parseInt(month,10), [4,6,9,11]) !== -1 ){\r\n        days_in_month = 30;\r\n    }\r\n\r\n    var $days_selector = $('select[name=birth_day]');\r\n\r\n    for( var i = $days_selector.children().length; i &lt; days_in_month; i++ ){\r\n        $days_selector.append('&lt;option value=&quot;'+(i+1)+'&quot;&gt;'+(i+1)+'&lt;\/option&gt;');\r\n    }\r\n\r\n    $days_selector.find('option:gt('+(days_in_month-1)+')').remove();\r\n    \r\n});\r\n\r\n<\/pre>\n<p>HTML Code:<\/p>\n<pre>\r\n\r\n&lt;select name=&quot;birth_year&quot;&gt;\r\n\t\t&lt;option value=&quot;1970&quot;&gt;1970&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1971&quot;&gt;1971&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1972&quot;&gt;1972&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1973&quot;&gt;1973&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1974&quot;&gt;1974&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1975&quot;&gt;1975&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1976&quot;&gt;1976&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1977&quot;&gt;1977&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1978&quot;&gt;1978&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1979&quot;&gt;1979&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1980&quot;&gt;1980&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1981&quot;&gt;1981&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1982&quot;&gt;1982&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1983&quot;&gt;1983&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1984&quot;&gt;1984&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1985&quot;&gt;1985&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1986&quot;&gt;1986&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1987&quot;&gt;1987&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1988&quot;&gt;1988&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1989&quot;&gt;1989&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1990&quot; selected&gt;1990&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1991&quot;&gt;1991&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1992&quot;&gt;1992&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1993&quot;&gt;1993&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1994&quot;&gt;1994&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1995&quot;&gt;1995&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1996&quot;&gt;1996&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1997&quot;&gt;1997&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1998&quot;&gt;1998&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;1999&quot;&gt;1999&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;2000&quot;&gt;2000&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;2001&quot;&gt;2001&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;2002&quot;&gt;2002&lt;\/option&gt;\r\n&lt;\/select&gt;\r\n&lt;select class=&quot;small&quot; name=&quot;birth_month&quot;&gt;\r\n\t\t&lt;option value=&quot;1&quot; selected&gt;1&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;2&quot;&gt;2&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;3&quot;&gt;3&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;4&quot;&gt;4&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;5&quot;&gt;5&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;6&quot;&gt;6&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;7&quot;&gt;7&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;8&quot;&gt;8&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;9&quot;&gt;9&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;10&quot;&gt;10&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;11&quot;&gt;11&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;12&quot;&gt;12&lt;\/option&gt;\r\n&lt;\/select&gt;\r\n&lt;select class=&quot;small&quot; name=&quot;birth_day&quot;&gt;\r\n\t\t&lt;option value=&quot;1&quot; selected&gt;1&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;2&quot;&gt;2&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;3&quot;&gt;3&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;4&quot;&gt;4&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;5&quot;&gt;5&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;6&quot;&gt;6&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;7&quot;&gt;7&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;8&quot;&gt;8&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;9&quot;&gt;9&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;10&quot;&gt;10&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;11&quot;&gt;11&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;12&quot;&gt;12&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;13&quot;&gt;13&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;14&quot;&gt;14&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;15&quot;&gt;15&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;16&quot;&gt;16&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;17&quot;&gt;17&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;18&quot;&gt;18&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;19&quot;&gt;19&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;20&quot;&gt;20&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;21&quot;&gt;21&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;22&quot;&gt;22&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;23&quot;&gt;23&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;24&quot;&gt;24&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;25&quot;&gt;25&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;26&quot;&gt;26&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;27&quot;&gt;27&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;28&quot;&gt;28&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;29&quot;&gt;29&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;30&quot;&gt;30&lt;\/option&gt;\r\n\t\t&lt;option value=&quot;31&quot;&gt;31&lt;\/option&gt;\r\n&lt;\/select&gt;\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JQuery Code: \/\/Adjust date picker days in month. $(&#8216;select[name=birth_year],select[name=birth_month]&#8217;).change(function(){ var year = $(&#8216;select[name=birth_year]&#8217;).val(); var month = $(&#8216;select[name=birth_month]&#8217;).val(); var days_in_month = 31; if( month == 2 &amp;&amp; year % 4 == 0 ){ days_in_month = 29; } else if( month == 2 &amp;&amp; year % 4 != 0 ){ days_in_month = 28; } else if( $.inArray(parseInt(month,10), &hellip; <a href=\"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Use JQuery to dynamically update day&#8217;s field when year\/month changes&#8221;<\/span><\/a><\/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-210","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Use JQuery to dynamically update day&#039;s field when year\/month changes - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Use JQuery to dynamically update day&#039;s field when year\/month changes - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2\" \/>\n<meta property=\"og:description\" content=\"JQuery Code: \/\/Adjust date picker days in month. $(&#039;select[name=birth_year],select[name=birth_month]&#039;).change(function(){ var year = $(&#039;select[name=birth_year]&#039;).val(); var month = $(&#039;select[name=birth_month]&#039;).val(); var days_in_month = 31; if( month == 2 &amp;&amp; year % 4 == 0 ){ days_in_month = 29; } else if( month == 2 &amp;&amp; year % 4 != 0 ){ days_in_month = 28; } else if( $.inArray(parseInt(month,10), &hellip; Continue reading &quot;Use JQuery to dynamically update day&#8217;s field when year\/month changes&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/\" \/>\n<meta property=\"og:site_name\" content=\"\u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-28T17:08:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-02-28T17:10:04+00:00\" \/>\n<meta name=\"author\" content=\"darkersss\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"darkersss\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/\",\"url\":\"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/\",\"name\":\"Use JQuery to dynamically update day's field when year\/month changes - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2\",\"isPartOf\":{\"@id\":\"https:\/\/www.369usa.com\/blog\/#website\"},\"datePublished\":\"2020-02-28T17:08:54+00:00\",\"dateModified\":\"2020-02-28T17:10:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/1c260c42af4aadda7f89a0081f6591b6\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.369usa.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Use JQuery to dynamically update day&#8217;s field when year\/month changes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.369usa.com\/blog\/#website\",\"url\":\"https:\/\/www.369usa.com\/blog\/\",\"name\":\"369\u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.369usa.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/1c260c42af4aadda7f89a0081f6591b6\",\"name\":\"darkersss\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2c538d84b753eed6f6f714becf9b3955?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2c538d84b753eed6f6f714becf9b3955?s=96&d=mm&r=g\",\"caption\":\"darkersss\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Use JQuery to dynamically update day's field when year\/month changes - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/","og_locale":"en_US","og_type":"article","og_title":"Use JQuery to dynamically update day's field when year\/month changes - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2","og_description":"JQuery Code: \/\/Adjust date picker days in month. $('select[name=birth_year],select[name=birth_month]').change(function(){ var year = $('select[name=birth_year]').val(); var month = $('select[name=birth_month]').val(); var days_in_month = 31; if( month == 2 &amp;&amp; year % 4 == 0 ){ days_in_month = 29; } else if( month == 2 &amp;&amp; year % 4 != 0 ){ days_in_month = 28; } else if( $.inArray(parseInt(month,10), &hellip; Continue reading \"Use JQuery to dynamically update day&#8217;s field when year\/month changes\"","og_url":"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/","og_site_name":"\u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2","article_published_time":"2020-02-28T17:08:54+00:00","article_modified_time":"2020-02-28T17:10:04+00:00","author":"darkersss","twitter_card":"summary_large_image","twitter_misc":{"Written by":"darkersss","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/","url":"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/","name":"Use JQuery to dynamically update day's field when year\/month changes - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2","isPartOf":{"@id":"https:\/\/www.369usa.com\/blog\/#website"},"datePublished":"2020-02-28T17:08:54+00:00","dateModified":"2020-02-28T17:10:04+00:00","author":{"@id":"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/1c260c42af4aadda7f89a0081f6591b6"},"breadcrumb":{"@id":"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.369usa.com\/blog\/use-jquery-to-dynamically-update-days-field-when-year-month-changes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.369usa.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Use JQuery to dynamically update day&#8217;s field when year\/month changes"}]},{"@type":"WebSite","@id":"https:\/\/www.369usa.com\/blog\/#website","url":"https:\/\/www.369usa.com\/blog\/","name":"369\u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.369usa.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/1c260c42af4aadda7f89a0081f6591b6","name":"darkersss","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2c538d84b753eed6f6f714becf9b3955?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2c538d84b753eed6f6f714becf9b3955?s=96&d=mm&r=g","caption":"darkersss"}}]}},"_links":{"self":[{"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/posts\/210"}],"collection":[{"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":2,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":212,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/posts\/210\/revisions\/212"}],"wp:attachment":[{"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}