{"id":3451,"date":"2015-11-06T17:41:37","date_gmt":"2015-11-06T23:41:37","guid":{"rendered":"http:\/\/neosmart.net\/blog\/?p=3451"},"modified":"2015-11-06T17:44:43","modified_gmt":"2015-11-06T23:44:43","slug":"a-smarter-month-and-year-input-field","status":"publish","type":"post","link":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/","title":{"rendered":"A smarter month and year input field: solving the credit card expiry conundrum"},"content":{"rendered":"<p>Every computer-savvy keyboarder has run into this problem before: you&#8217;re typing your merry way through a credit card payment form, pounding out your address and credit card numbers, tabbing between the fields so you don&#8217;t waste time mucking around with the mouse, when you come across the dreaded expiry date fields:<\/p>\n<p><a href=\"\/blog\/wp-content\/uploads\/Expiry-Date-Fields.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3452 colorbox-3451\" src=\"\/blog\/wp-content\/uploads\/Expiry-Date-Fields.png\" alt=\"Expiry Date Fields\" width=\"305\" height=\"147\" srcset=\"https:\/\/neosmart.net\/blog\/wp-content\/uploads\/Expiry-Date-Fields.png 610w, https:\/\/neosmart.net\/blog\/wp-content\/uploads\/Expiry-Date-Fields-500x241.png 500w\" sizes=\"auto, (max-width: 305px) 100vw, 305px\" \/><\/a><\/p>\n<p>You groan. You know what&#8217;s coming next. Your card expires in April of 2019. Are they expecting you to type &#8216;A&#8217; for &#8220;April&#8221; or to key in &#8220;04&#8221;? Or maybe it&#8217;s just &#8216;4&#8217;? Murphy&#8217;s law guarantees\u00a0that whatever sequence you try typing these options in, it&#8217;ll be the last one you try. You sigh. You either try the different options haphazardly, holding your breath and cringing when it doesn&#8217;t change, or changes to select the wrong value. Finally, you give up and move your hand those excruciatingly-far 6&#8243; to the mouse, and sigh in despair as you resort to clicking on the drop-down box and scrolling through the entries to select the one you&#8217;re looking for.<\/p>\n<p><!--more--><\/p>\n<p>What if I told you there was a better way? And, no, it&#8217;s not doing something like graying-out some sample placeholder text and hoping your customers won&#8217;t be confused, thinking that was a pre-selected month\/year. Here, try it out yourself. Just click in the first input field (&#8220;Just a place for you to start tabbing&#8230;&#8221;) then &lt;tab&gt; your way across the rest of the form and key your choice of month and year, in <em>any<\/em> format you like. The form will magically change itself based on who you are and what kind of preferences you have, and it&#8217;ll change accordingly to make sure that whatever you end up typing will work!<\/p>\n<p><iframe width=\"100%\" src=\"\/\/jsfiddle.net\/mqudsi\/3u1x2pue\/embedded\/result\/\" allowfullscreen=\"allowfullscreen\" frameborder=\"0\" style=\"height: 150px\"><\/iframe><\/p>\n<p>Oh my gosh! How did that work? Well, it didn&#8217;t really read your mind and it&#8217;s actually not magic (even if it seems that way) (and despite what I said before). It&#8217;s quite simple: the list actually contains all the variations of the month and year formats:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/mqudsi\/129799041682fb3a3531.js\"><\/script><\/p>\n<p>Then, with some clever javascript magic, we match up whatever the user selected to the &#8220;proper&#8221; format we wish the dropdown menu to show when they navigate away from the entry field. But it would be <em>extremely<\/em> confusing to less tech-savvy users if their drop-down contained multiple options evaluating to the same month &#8211; when you have to choose between &#8220;January&#8221;, &#8220;01&#8221;, and &#8220;1&#8221;, which do you choose? So the javascript hides the not &#8220;proper&#8221; options each time the drop-down menu is opened (via clicking or by hitting the spacebar) and returns the values when the menu is closed once more!<\/p>\n<p>Here&#8217;s the full javascript code to pull this off. It&#8217;s using jquery, but there&#8217;s absolutely nothing complicated in there and it can be easily rewritten to use plain old javascript instead (it&#8217;s a GitHub gist, so anyone willing to do so, fork away!):<\/p>\n<p><script src=\"https:\/\/gist.github.com\/mqudsi\/6cec1827ef931eed69d0.js\"><\/script><\/p>\n<p>Each time the menu is opened, any &lt;option&gt; tagged with the class &#8220;extraneous&#8221; is detached from the parent &lt;select&gt; and stored in an array associated with the self-same &lt;select&gt;. Each time the user navigates away from the &lt;select&gt;, the drop-down menu is re-populated with the previously-removed elements. It works like magic on any &lt;select&gt; tagged with the class &#8220;magic&#8221; and should be fairly reliable! We&#8217;ve been using this code on the checkout page in <a href=\"\/Store\/\">both<\/a> our <a href=\"\/EasyRE\/\">online stores<\/a> for the past few years and it&#8217;s been working great. Well enough, in fact, that we decided to share it with everyone!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every computer-savvy keyboarder has run into this problem before: you&#8217;re typing your merry way through a credit card payment form, pounding out your address and credit card numbers, tabbing between the fields so you don&#8217;t waste time mucking around with &hellip; <a href=\"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":505,"featured_media":0,"comment_status":"open","ping_status":"closed","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_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[76,11,430,905,177],"class_list":["post-3451","post","type-post","status-publish","format-standard","hentry","category-software","tag-javascript","tag-programming","tag-user-interface","tag-ux","tag-web-development"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Every computer-savvy keyboarder has run into this problem before: you&#039;re typing your merry way through a credit card payment form, pounding out your address and credit card numbers, tabbing between the fields so you don&#039;t waste time mucking around with the mouse, when you come across the dreaded expiry date fields: You groan. You know\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Mahmoud Al-Qudsi\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/#article\",\"name\":\"A smarter month and year input field: solving the credit card expiry conundrum | The NeoSmart Files\",\"headline\":\"A smarter month and year input field: solving the credit card expiry conundrum\",\"author\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/author\\\/mqudsi\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"\\\/blog\\\/wp-content\\\/uploads\\\/Expiry-Date-Fields.png\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/#articleImage\"},\"datePublished\":\"2015-11-06T17:41:37-06:00\",\"dateModified\":\"2015-11-06T17:44:43-06:00\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/#webpage\"},\"articleSection\":\"Software, javascript, programming, user interface, ux, web development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/category\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/category\\\/software\\\/#listItem\",\"position\":2,\"name\":\"Software\",\"item\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/category\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/#listItem\",\"name\":\"A smarter month and year input field: solving the credit card expiry conundrum\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/#listItem\",\"position\":3,\"name\":\"A smarter month and year input field: solving the credit card expiry conundrum\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/category\\\/software\\\/#listItem\",\"name\":\"Software\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#organization\",\"name\":\"The NeoSmart Files\",\"description\":\"Recovery software and more\",\"url\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/author\\\/mqudsi\\\/#author\",\"url\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/author\\\/mqudsi\\\/\",\"name\":\"Mahmoud Al-Qudsi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c2643dd7c6df61aed49d9f3d917ac6d61cafbbda5f9b1619f50d3b749dca415a?s=96&d=mm&r=pg\",\"width\":96,\"height\":96,\"caption\":\"Mahmoud Al-Qudsi\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/#webpage\",\"url\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/\",\"name\":\"A smarter month and year input field: solving the credit card expiry conundrum | The NeoSmart Files\",\"description\":\"Every computer-savvy keyboarder has run into this problem before: you're typing your merry way through a credit card payment form, pounding out your address and credit card numbers, tabbing between the fields so you don't waste time mucking around with the mouse, when you come across the dreaded expiry date fields: You groan. You know\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/a-smarter-month-and-year-input-field\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/author\\\/mqudsi\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/author\\\/mqudsi\\\/#author\"},\"datePublished\":\"2015-11-06T17:41:37-06:00\",\"dateModified\":\"2015-11-06T17:44:43-06:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/\",\"name\":\"The NeoSmart Files\",\"description\":\"Recovery software and more\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/neosmart.net\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"A smarter month and year input field: solving the credit card expiry conundrum | The NeoSmart Files","description":"Every computer-savvy keyboarder has run into this problem before: you're typing your merry way through a credit card payment form, pounding out your address and credit card numbers, tabbing between the fields so you don't waste time mucking around with the mouse, when you come across the dreaded expiry date fields: You groan. You know","canonical_url":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/#article","name":"A smarter month and year input field: solving the credit card expiry conundrum | The NeoSmart Files","headline":"A smarter month and year input field: solving the credit card expiry conundrum","author":{"@id":"https:\/\/neosmart.net\/blog\/author\/mqudsi\/#author"},"publisher":{"@id":"https:\/\/neosmart.net\/blog\/#organization"},"image":{"@type":"ImageObject","url":"\/blog\/wp-content\/uploads\/Expiry-Date-Fields.png","@id":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/#articleImage"},"datePublished":"2015-11-06T17:41:37-06:00","dateModified":"2015-11-06T17:44:43-06:00","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/#webpage"},"isPartOf":{"@id":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/#webpage"},"articleSection":"Software, javascript, programming, user interface, ux, web development"},{"@type":"BreadcrumbList","@id":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/neosmart.net\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/category\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/category\/software\/#listItem","position":2,"name":"Software","item":"https:\/\/neosmart.net\/blog\/category\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/#listItem","name":"A smarter month and year input field: solving the credit card expiry conundrum"},"previousItem":{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/#listItem","position":3,"name":"A smarter month and year input field: solving the credit card expiry conundrum","previousItem":{"@type":"ListItem","@id":"https:\/\/neosmart.net\/blog\/category\/software\/#listItem","name":"Software"}}]},{"@type":"Organization","@id":"https:\/\/neosmart.net\/blog\/#organization","name":"The NeoSmart Files","description":"Recovery software and more","url":"https:\/\/neosmart.net\/blog\/"},{"@type":"Person","@id":"https:\/\/neosmart.net\/blog\/author\/mqudsi\/#author","url":"https:\/\/neosmart.net\/blog\/author\/mqudsi\/","name":"Mahmoud Al-Qudsi","image":{"@type":"ImageObject","@id":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/c2643dd7c6df61aed49d9f3d917ac6d61cafbbda5f9b1619f50d3b749dca415a?s=96&d=mm&r=pg","width":96,"height":96,"caption":"Mahmoud Al-Qudsi"}},{"@type":"WebPage","@id":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/#webpage","url":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/","name":"A smarter month and year input field: solving the credit card expiry conundrum | The NeoSmart Files","description":"Every computer-savvy keyboarder has run into this problem before: you're typing your merry way through a credit card payment form, pounding out your address and credit card numbers, tabbing between the fields so you don't waste time mucking around with the mouse, when you come across the dreaded expiry date fields: You groan. You know","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/neosmart.net\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/#breadcrumblist"},"author":{"@id":"https:\/\/neosmart.net\/blog\/author\/mqudsi\/#author"},"creator":{"@id":"https:\/\/neosmart.net\/blog\/author\/mqudsi\/#author"},"datePublished":"2015-11-06T17:41:37-06:00","dateModified":"2015-11-06T17:44:43-06:00"},{"@type":"WebSite","@id":"https:\/\/neosmart.net\/blog\/#website","url":"https:\/\/neosmart.net\/blog\/","name":"The NeoSmart Files","description":"Recovery software and more","inLanguage":"en-US","publisher":{"@id":"https:\/\/neosmart.net\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"3451","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2020-12-23 20:07:01","updated":"2026-01-10 22:13:45","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/neosmart.net\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/neosmart.net\/blog\/category\/software\/\" title=\"Software\">Software<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tA smarter month and year input field: solving the credit card expiry conundrum\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/neosmart.net\/blog\/"},{"label":"Software","link":"https:\/\/neosmart.net\/blog\/category\/software\/"},{"label":"A smarter month and year input field: solving the credit card expiry conundrum","link":"https:\/\/neosmart.net\/blog\/a-smarter-month-and-year-input-field\/"}],"jetpack_shortlink":"https:\/\/wp.me\/p4xDa-TF","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/users\/505"}],"replies":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/comments?post=3451"}],"version-history":[{"count":27,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3451\/revisions"}],"predecessor-version":[{"id":3479,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3451\/revisions\/3479"}],"wp:attachment":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/media?parent=3451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/categories?post=3451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/tags?post=3451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}