{"id":3551,"date":"2015-04-16T12:15:27","date_gmt":"2015-04-16T09:15:27","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=3551"},"modified":"2017-12-19T14:05:29","modified_gmt":"2017-12-19T12:05:29","slug":"html5-input-types-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/","title":{"rendered":"HTML5 Input Types Example"},"content":{"rendered":"<p>If you are developing web applications, you may have created forms, at least for a contact page, or even a login page. So I suppose you should know how to create a form, and the major field you can add such as text element, password field, or other checkboxes and radio buttons. Of course you will add a submit button to submit data to the server, and maybe a reset button i you want to play the old school way.<\/p>\n<p>HTML5 introduced more than twelve new types of input, and you can use them! Yes, even if they are not fully supported by the browser you&#8217;re using, they will be treated as an input type text, so yes you can use them in your web pages.<\/p>\n<p>So in this article we will present you those new element types: <\/p>\n<p>[one_third]<\/p>\n<ul>\n<li><a href=\"#color\">color<\/a><\/li>\n<li><a href=\"#date\">date<\/a><\/li>\n<li><a href=\"#datetime\">datetime<\/a><\/li>\n<li><a href=\"#datetime-local\">datetime-local<\/a><\/li>\n<\/ul>\n<p>[\/one_third]<\/p>\n<p>[one_third]<\/p>\n<ul>\n<li><a href=\"#email\">email<\/a><\/li>\n<li><a href=\"#month\">month<\/a><\/li>\n<li><a href=\"#number\">number<\/a><\/li>\n<li><a href=\"#range\">range<\/a><\/li>\n<li><a href=\"#search\">search<\/a><\/li>\n<ul>\n[\/one_third]<\/p>\n<p>[one_third_last]<\/p>\n<ul>\n<li><a href=\"#tel\">tel<\/a><\/li>\n<li><a href=\"#time\">time<\/a><\/li>\n<li><a href=\"#url\">url<\/a><\/li>\n<li><a href=\"#week\">week<\/a><\/li>\n<\/ul>\n<p>[\/one_third_last]<br \/>\n[ulp id=&#8217;tgm4cmEWcKUikZNn&#8217;]<\/p>\n<h2><a name=\"color\"><\/a>1. The input type color : <\/h2>\n<h3>1.1 Presentation<\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;color&quot;\/&gt;\r\n<\/pre>\n<p>This type will allow the user to select a color using the system color picker.<\/p>\n<p><strong>Note : <\/strong> this type is not implemented in all browser, check availability on the <a href=\"http:\/\/caniuse.com\/#feat=input-color\">can-i-use web site<\/a>.<\/p>\n<h3>1.2 Javascript<\/h3>\n<p>The color selected by the user will be accessible via the <code>value<\/code> attribute. And in order to set the color,<br \/>\nsimply set the <code>value<\/code> attribute, let see an example :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n(function(){\r\n    var colorElement = document.getElementById('colorinput');\r\n    \/\/ Set the color to red\r\n    colorElement.value=&quot;#FF0000&quot;;\r\n\r\n    \/\/ Log the new color on change\r\n    colorElement.addEventListener('change', function(e){\r\n       console.log(colorElement.value);\r\n    });\r\n})();\r\n<\/pre>\n<blockquote><p><strong>Note<\/strong> : The browsers may set the value to <code>#000000<\/code> if you try to set an invalid color string.\n<\/p><\/blockquote>\n<h2><a name=\"date\"><\/a>2. The input type date: <\/h2>\n<h3>2.1 Presentation <\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;date&quot;\/&gt;\r\n<\/pre>\n<p>The <code>date<\/code> attribute will define a string representing a specific date.<\/p>\n<p><strong>Note : <\/strong> this type is not implemented in all browser, check availability on the <a href=\"http:\/\/caniuse.com\/#feat=input-datetime\">can-i-use web site<\/a>.<\/p>\n<p>For example, in Chrome, when using this attribute, the browser will present you a calendar to select a date :<\/p>\n<figure id=\"attachment_3554\" aria-describedby=\"caption-attachment-3554\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/date.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/date.png\" alt=\"Input type date example\" width=\"800\" height=\"602\" class=\"size-full wp-image-3554\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/date.png 800w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/date-300x226.png 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-3554\" class=\"wp-caption-text\">Input type date<\/figcaption><\/figure>\n<h3>2.2 Javascript<\/h3>\n<p>The date selected (or entered) by the user will be accessible via the <code>value<\/code> attribute.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n(function(){\r\n    var dateElement = document.getElementById('dateinput');\r\n    dateElement.addEventListener('change', function(e){\r\n        console.log(dateElement.value);\r\n\r\n        \/\/ Get the value as a Date Object\r\n        console.log(dateElement.valueAsDate);\r\n\r\n        \/\/ Get the value as a number (timestamp)\r\n        console.log(dateElement.valueAsNumber);\r\n    });\r\n})();\r\n<\/pre>\n<blockquote><p><strong>Note<\/strong> : The browser (if it supports the attribute) won&#8217;t allow you to set a date that is not a valid date string.\n<\/p><\/blockquote>\n<h3>2.3 Other attributes<\/h3>\n<p> This type allow you to define constraints by adding some attributes :<\/p>\n<ul>\n<li><code>min<\/code> : The Minimum date, as a string, the browser won&#8217;t permit the selection of a date before the minimum.\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;input type=&quot;date&quot; min=&quot;2015-04-01&quot;\/&gt;<\/pre>\n<\/li>\n<li><code>max<\/code> : The Maximuim date, as a string, the browser won&#8217;t permit the selection of a date after the maximum.\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;input type=&quot;date&quot; max=&quot;2015-04-10&quot;  min=&quot;2015-04-01&quot;\/&gt;<\/pre>\n<\/li>\n<li><code>step<\/code> : when define,  the browser will start at a date (today, or the date define in the minimum attribute) and allow only date separated by &#8220;step&#8221; days.\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;input type=&quot;date&quot; step=&quot;10&quot; \/&gt;<\/pre>\n<\/li>\n<\/ul>\n<h2><a name=\"datetime\"><\/a>3. The input type datetime : <\/h2>\n<h3>3.1 Presentation <\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;datetime&quot;\/&gt;\r\n<\/pre>\n<p>This will allow you to enter a date and time (hour, minute, second, and fraction of a second) based on UTC time zone.<\/p>\n<blockquote><p><strong>Note <\/strong> : None of my browsers supported this value<\/p><\/blockquote>\n<h2><a name=\"datetime-local\"><\/a>4. The input type datetime-local : <\/h2>\n<h3>4.1 Presentation <\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;datetime-local&quot; id=&quot;dateinput1&quot; \/&gt;\r\n<\/pre>\n<p>This will allow you to enter a date and time (hour, minute, second, and fraction of a second) based on local time zone.<\/p>\n<figure id=\"attachment_3555\" aria-describedby=\"caption-attachment-3555\" style=\"width: 799px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/datetime.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/datetime.png\" alt=\"input type datetime example\" width=\"799\" height=\"599\" class=\"size-full wp-image-3555\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/datetime.png 799w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/datetime-300x225.png 300w\" sizes=\"(max-width: 799px) 100vw, 799px\" \/><\/a><figcaption id=\"caption-attachment-3555\" class=\"wp-caption-text\">input type datetime<\/figcaption><\/figure>\n<h3>4.2 Javascript<\/h3>\n<p>The date selected (or entered) by the user will be accessible via the <code>value<\/code> attribute.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n(function(){\r\n    var dateElement = document.getElementById('dateinput1');\r\n    dateElement.addEventListener('change', function(e){\r\n        console.log(dateElement.value);\r\n\r\n        \/\/ Get the value as a number (timestamp)\r\n        console.log(dateElement.valueAsNumber);\r\n    });\r\n})();\r\n<\/pre>\n<h2><a name=\"email\"><\/a>5. The input type email : <\/h2>\n<h3>5.1 Presentation <\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;email&quot;  \/&gt;\r\n<\/pre>\n<p>This will allow you to enter an email address.<\/p>\n<p>There is no specific representation of this field, it is shown as an input type text element. But on mobile devices, the keyboard displayed when the user wants to enter some text in this type of field will add some special characters such as the <em>@<\/em> or <em>.com<\/em>.<\/p>\n<h3>5.2 Javascript<\/h3>\n<p>The email entered by the user will be accessible via the <code>value<\/code> attribute.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n(function(){\r\n    var emailElement = document.getElementById('mail1');\r\n    emailElement.addEventListener('change', function(e){\r\n       console.log(emailElement.value);\r\n    });\r\n})();\r\n<\/pre>\n<h3>5.3 CSS Pseudo Elements<\/h3>\n<p>In order to display the validation status of the element you can use the CSS 3 pseudo elements : <code>:invalid<\/code> and <code>:valid<\/code><\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\ninput&#x5B;type='email']:invalid {\r\n    color:red;\r\n}\r\n\r\ninput&#x5B;type='email']:valid {\r\n    color:green;\r\n}\r\n<\/pre>\n<h2><a name=\"month\"><\/a>6. The input type month :<\/h2>\n<h3>6.1 Presentation <\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;month&quot;\/&gt;\r\n<\/pre>\n<p>This will allow you to enter a month and a year without timezone.<\/p>\n<blockquote><p><strong>Note<\/strong> : The browser (if it supports the attribute) won&#8217;t allow you to set a month that is not a valid month string.\n<\/p><\/blockquote>\n<blockquote><p><strong>Note<\/strong> : This type, will accept the same attributes as the <code>date<\/code> type, ie : <code>min<\/code>, <code>max<\/code> and <code>step<\/code>. Here the value <em>1<\/em> for <code>step<\/code> represents a month.<\/p><\/blockquote>\n<figure id=\"attachment_3556\" aria-describedby=\"caption-attachment-3556\" style=\"width: 801px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/month.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/month.png\" alt=\"input type month example\" width=\"801\" height=\"597\" class=\"size-full wp-image-3556\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/month.png 801w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/month-300x224.png 300w\" sizes=\"(max-width: 801px) 100vw, 801px\" \/><\/a><figcaption id=\"caption-attachment-3556\" class=\"wp-caption-text\">input type month<\/figcaption><\/figure>\n<h3>6.2 Javascript<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n     (function () {\r\n\r\n        var element = document.getElementById('input1');\r\n        element.addEventListener('change', function (e) {\r\n            \/\/ Retreive the value\r\n            console.log(element.value); \/\/ 2015-04\r\n\r\n            \/\/ Set a ne Value\r\n            element.value = &quot;2015-06&quot;;\r\n\r\n            \/\/ Log the value as Date (First of June ...)\r\n            console.log(element.valueAsDate);\r\n\r\n        });\r\n    })();\r\n    <\/pre>\n<h2><a name=\"number\"><\/a>7. The input type number :<\/h2>\n<h3>7.1 Presentation<\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;number&quot;\/&gt;\r\n<\/pre>\n<p>This type will create a control, to only accept a numerical value.<\/p>\n<blockquote><p><strong>Note<\/strong> : On Mobile devices, this input type, will make the device to show the numeric keyboard when the user wants to enter a value in the field.<\/p><\/blockquote>\n<h3>7.2 Javascript<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n (function () {\r\n\r\n    var element = document.getElementById('input1');\r\n    element.addEventListener('change', function (e) {\r\n        \/\/ Retreive the value\r\n        console.log(element.value); \/\/ 2\r\n    });\r\n})();\r\n<\/pre>\n<h3>7.3 Attributes and CSS<\/h3>\n<h4>Attributes<\/h4>\n<ul>\n<li><code>min<\/code> : The Minimum Number\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;input type=&quot;number&quot; min=&quot;0&quot;\/&gt;<\/pre>\n<\/li>\n<li><code>max<\/code> : The Maximuim Nuhmber\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;input type=&quot;date&quot; max=&quot;100&quot;  min=&quot;0&quot;\/&gt;<\/pre>\n<\/li>\n<li><code>step<\/code> : when define, the browser will not accept any value that are not separated from step (form 0 or min). This can be use to allow the user to enter a decimal value.\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;input type=&quot;date&quot; step=&quot;0.1&quot; \/&gt;<\/pre>\n<\/li>\n<\/ul>\n<h4>CSS Pseudo Elements<\/h4>\n<p>In order to display the validation status of the element you can use the CSS3 pseudo elements : <code>:invalid<\/code> and <code>:valid<\/code><\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\ninput:invalid {\r\n    color:red;\r\n}\r\ninput:valid {\r\n    color:green;\r\n}\r\n<\/pre>\n<h2><a name=\"range\"><\/a>8. The input type range : <\/h2>\n<h3>8.1 Presentation<\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;range&quot;\/&gt;\r\n<\/pre>\n<p>This type create a control, that will display a slider to define a value. Usefull for entering a number whose exact value is not really important.<\/p>\n<p>The default values for the attributes are :<\/p>\n<ul>\n<li><code>min<\/code> : 0<\/li>\n<li><code>max<\/code> : 100<\/li>\n<li><code>value<\/code> : min + (max-min)\/2, or min if max is less than min<\/li>\n<li><code>step<\/code> : 1<\/li>\n<\/ul>\n<figure id=\"attachment_3557\" aria-describedby=\"caption-attachment-3557\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/range.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/range.png\" alt=\"input type range example\" width=\"800\" height=\"600\" class=\"size-full wp-image-3557\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/range.png 800w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/range-300x225.png 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-3557\" class=\"wp-caption-text\">input type range<\/figcaption><\/figure>\n<h3>8.2 Javascript<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n (function () {\r\n    var element = document.getElementById('input1');\r\n    element.addEventListener('change', function (e) {\r\n        \/\/ Retreive the value\r\n        console.log(element.value); \/\/ 2\r\n    });\r\n})();\r\n<\/pre>\n<h2><a name=\"search\"><\/a>9. The input type search :<\/h2>\n<h3>9.1 Presentation<\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;search&quot;\/&gt;\r\n<\/pre>\n<p>This type, is a kind of input type <code>text<\/code>, except that when the value entered in this input contains line breaks, they are automatically removed from the value sent to the server.<\/p>\n<h3>9.2 Javascript<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n (function () {\r\n    var element = document.getElementById('input1');\r\n    element.addEventListener('change', function (e) {\r\n        \/\/ Retreive the value\r\n        console.log(element.value); \/\/ 2\r\n    });\r\n})();\r\n<\/pre>\n<h2><a name=\"tel\"><\/a>10. The input type tel : <\/h2>\n<h3>10.1 Presentation<\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;tel&quot;\/&gt;\r\n<\/pre>\n<p>This will help you to enter a phone number.<\/p>\n<blockquote><p><strong>Note<\/strong> : There is no specificities for this element except that on mobile devices the numeric keyboard will be displayed when user want to enter a phone number.<\/p><\/blockquote>\n<h3>10.2 Javascript<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n (function () {\r\n    var element = document.getElementById('input1');\r\n    element.addEventListener('change', function (e) {\r\n        \/\/ Retreive the value\r\n        console.log(element.value); \/\/ 2\r\n    });\r\n})();\r\n<\/pre>\n<h2><a name=\"time\"><\/a>11. The input type time :<\/h2>\n<h3>11.1 Presentation <\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;time&quot;\/&gt;\r\n<\/pre>\n<p>This will allow you to enter an hour without timezone.<\/p>\n<blockquote><p><strong>Note<\/strong> : The browser (if it supports the attribute) won&#8217;t allow you to set an hour that is not a valid hour  string.\n<\/p><\/blockquote>\n<blockquote><p><strong>Note<\/strong> : This type, will accept the same attributes as the <code>date<\/code> type, ie : <code>min<\/code>, <code>max<\/code> and <code>step<\/code>. Here the value <em>1<\/em> for <code>step<\/code> represents a second, default is 60 seconds.<\/p><\/blockquote>\n<h3>11.2 Javascript<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n     (function () {\r\n         var element = document.getElementById('input1');\r\n        element.addEventListener('change', function (e) {\r\n            \/\/ Retreive the value\r\n            console.log(element.value); \/\/ 10:00\r\n\r\n            \/\/ Set Value to last time of year\r\n            element.value = &quot;16:45&quot;;\r\n        });\r\n    })();\r\n    <\/pre>\n<h2><a name=\"url\"><\/a>12. The input type url : <\/h2>\n<h3>12.1 Presentation<\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;url&quot;\/&gt;\r\n<\/pre>\n<p>This attribute act as the <code>email<\/code> attribute.<\/p>\n<p>This will allow you to enter an url (with schema : http, ftp &#8230;).<\/p>\n<p>There is no specific representation of this field, it is shown as an input type text element. But on mobile devices, the keyboard displayed when the user wants to enter some text in this type of field will add some special characters such as <em>.com<\/em> and <em>http:\/\/<\/em>.<\/p>\n<h3>12.2 Javascript<\/h3>\n<p>The url entered by the user will be accessible via the <code>value<\/code> attribute.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n(function(){\r\n    var urlElement = document.getElementById('url1');\r\n    urlElement.addEventListener('change', function(e){\r\n       console.log(urlElement.value);\r\n    });\r\n})();\r\n<\/pre>\n<h3>12.3 CSS Pseudo Elements<\/h3>\n<p>In order to display the validation status of the element you can use the CSS 3 pseudo elements : <code>:invalid<\/code> and <code>:valid<\/code><\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\ninput&#x5B;type='url']:invalid {\r\n    color:red;\r\n}\r\n\r\ninput&#x5B;type='url']:valid {\r\n    color:green;\r\n}\r\n<\/pre>\n<h2><a name=\"week\"><\/a>13. The input type week : <\/h2>\n<h3>13.1 Presentation <\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;week&quot;\/&gt;\r\n<\/pre>\n<p>This will allow you to enter a week and a year without timezone.<\/p>\n<blockquote><p><strong>Note<\/strong> : The browser (if it supports the attribute) won&#8217;t allow you to set a week that is not a valid week string.\n<\/p><\/blockquote>\n<blockquote><p><strong>Note<\/strong> : This type, will accept the same attributes as the <code>date<\/code> type, ie : <code>min<\/code>, <code>max<\/code> and <code>step<\/code>. Here the value <em>1<\/em> for <code>step<\/code> represents a week.<\/p><\/blockquote>\n<figure id=\"attachment_3558\" aria-describedby=\"caption-attachment-3558\" style=\"width: 798px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/week.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/week.png\" alt=\"input type week example\" width=\"798\" height=\"600\" class=\"size-full wp-image-3558\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/week.png 798w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/week-300x226.png 300w\" sizes=\"(max-width: 798px) 100vw, 798px\" \/><\/a><figcaption id=\"caption-attachment-3558\" class=\"wp-caption-text\">input type week<\/figcaption><\/figure>\n<h3>13.2 Javascript<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n     (function () {\r\n        var element = document.getElementById('input1');\r\n        element.addEventListener('change', function (e) {\r\n            \/\/ Retreive the value\r\n            console.log(element.value); \/\/ 2015-W15\r\n\r\n            \/\/ Set Value to last week of year\r\n            element.value = &quot;2015-W52&quot;;\r\n\r\n            \/\/ Log the value as Date, this return the first day of the Week\r\n            console.log(element.valueAsDate);\r\n\r\n        });\r\n    })();\r\n    <\/pre>\n<h2>14. Download<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\n    You can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/html5_input_type_example.zip\"><strong>HTML5 Input Type Example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you are developing web applications, you may have created forms, at least for a contact page, or even a login page. So I suppose you should know how to create a form, and the major field you can add such as text element, password field, or other checkboxes and radio buttons. Of course you &hellip;<\/p>\n","protected":false},"author":46,"featured_media":914,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-3551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-html5"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>HTML5 Input type example<\/title>\n<meta name=\"description\" content=\"This article describe the input type introduced with HTML5 by example\" \/>\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.webcodegeeks.com\/html5\/html5-input-types-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HTML5 Input type example\" \/>\n<meta property=\"og:description\" content=\"This article describe the input type introduced with HTML5 by example\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-04-16T09:15:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-19T12:05:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Remi Goyard\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mimiz33\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Remi Goyard\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/\"},\"author\":{\"name\":\"Remi Goyard\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242\"},\"headline\":\"HTML5 Input Types Example\",\"datePublished\":\"2015-04-16T09:15:27+00:00\",\"dateModified\":\"2017-12-19T12:05:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/\"},\"wordCount\":1766,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"articleSection\":[\"HTML5\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/\",\"name\":\"HTML5 Input type example\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"datePublished\":\"2015-04-16T09:15:27+00:00\",\"dateModified\":\"2017-12-19T12:05:29+00:00\",\"description\":\"This article describe the input type introduced with HTML5 by example\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HTML5\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/html5\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"HTML5 Input Types Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242\",\"name\":\"Remi Goyard\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g\",\"caption\":\"Remi Goyard\"},\"description\":\"I'm a senior web architect. Passionated by new technologies, programming, devops tools, and agile methodologies. I really enjoy to coach, or teach, people who wants to learn programming, from beginners to skilled programmers. Involved in local developer communities, Java User Group, PHP User Group, or Javascript User Group, i like to share with others about experiences, news or business. Coding is FUN !\",\"sameAs\":[\"http:\/\/www.mimiz.fr\/\",\"http:\/\/fr.linkedin.com\/in\/remigoyard\/en\",\"https:\/\/x.com\/@mimiz33\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/remi-goyard\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HTML5 Input type example","description":"This article describe the input type introduced with HTML5 by example","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.webcodegeeks.com\/html5\/html5-input-types-example\/","og_locale":"en_US","og_type":"article","og_title":"HTML5 Input type example","og_description":"This article describe the input type introduced with HTML5 by example","og_url":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2015-04-16T09:15:27+00:00","article_modified_time":"2017-12-19T12:05:29+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","type":"image\/jpeg"}],"author":"Remi Goyard","twitter_card":"summary_large_image","twitter_creator":"@mimiz33","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Remi Goyard","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/"},"author":{"name":"Remi Goyard","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242"},"headline":"HTML5 Input Types Example","datePublished":"2015-04-16T09:15:27+00:00","dateModified":"2017-12-19T12:05:29+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/"},"wordCount":1766,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","articleSection":["HTML5"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/","url":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/","name":"HTML5 Input type example","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","datePublished":"2015-04-16T09:15:27+00:00","dateModified":"2017-12-19T12:05:29+00:00","description":"This article describe the input type introduced with HTML5 by example","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-input-types-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"HTML5","item":"https:\/\/www.webcodegeeks.com\/category\/html5\/"},{"@type":"ListItem","position":3,"name":"HTML5 Input Types Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242","name":"Remi Goyard","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g","caption":"Remi Goyard"},"description":"I'm a senior web architect. Passionated by new technologies, programming, devops tools, and agile methodologies. I really enjoy to coach, or teach, people who wants to learn programming, from beginners to skilled programmers. Involved in local developer communities, Java User Group, PHP User Group, or Javascript User Group, i like to share with others about experiences, news or business. Coding is FUN !","sameAs":["http:\/\/www.mimiz.fr\/","http:\/\/fr.linkedin.com\/in\/remigoyard\/en","https:\/\/x.com\/@mimiz33"],"url":"https:\/\/www.webcodegeeks.com\/author\/remi-goyard\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/3551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=3551"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/3551\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/914"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=3551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=3551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=3551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}