How to use year input type in HTML?

HTMLWeb DevelopmentFront End Technology

The month input type is used in HTML using the <input type = "month">. Using this, allow the users to select month and year. But, what if you only want to show the year popup? Well, year input type isn’t available.

To use year input type, we will be using jQuery to add datepicker. It is used with the text input type. On running the program, only the year will be visible.

You can try to run the following code to learn how to use input type to set a year

Example

Live Demo

<html>
   <head>
      <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js">
      </script>
      <script type="text/javascript">
         $(function() {
            $( "#date" ).datepicker({dateFormat: 'yy'});
         });
      </script>
   </head>
   <body>
      <form action = "" method = "get">
         Details:<br> <br>
         Student Name <br> <input type="name" name="sname"> <br>
         Year of Birth <br> <input type="text" id="date"> <br>
         <input type="submit" value="Submit">
      </form>
   </body>
</html>
raja
Published on 07-Feb-2018 12:43:17
Advertisements