How to use month input type in HTML?

PHPz
Release: 2023-08-20 20:21:16
forward
902 people have browsed it

In HTML, a form of various elements which helps in making a user interface in a web page. Using which we can collect different nature of nature.

One of the commonly used control is Month control i.e.

This control basically provides the user with a calendar-like drop-down menu from which the user can select or select the month and year. Month The control allows you to select a date in the format YYYY-MM, where YYYY represents the year and MM represents the month.

Let's look at a simple example using the Month control.

Example

<html>
<body>
   <form name="form1">
      <label for="adm">Date of Admission:</label>
      <input type="month" name="doa">
   </form>
</body>
</html>
Copy after login

Executing the code given above, a month control will be displayed on the page.

When you click on the calendar icon on the right side of the control, it will open the complete month calendar like this −

How to use month input type in HTML?

Once the drop-down menu opens, you can select the month and year from the calendar, or you can enter the month and year in the control.

Once the month and year is selected, it will get stored in String type of value.

Let us create a program to display the selected month and year from the control using JavaScript.

Example

<html>
<head>
   <title>Admission Form</title>
   <script>
      function display(){
         d=form1.doa.value;
         document.write("<center><b>Date of Admission is "+d 
         +"</b></center>");
      }
   </script>
   <form name="form1">
 	   <label for="adm">Date of Admission:</label>
	   <input type="month" name="doa" onchange="display()">
   </form>
<html>
Copy after login

In this program, we have used

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!