Search code examples
htmlformshtml-formhandler

Is there a way to display the form field as mm/yyyy in html form?


I'm trying to have a form field with mm/yyyy as an input. Can you help me in suggesting a way to have this date format ?


Solution

  • In your html code use the input element and give it the "month" type (YYYY-MM)

    <input type="month" id="something" />
    

    To get the date and year, you can use javascript

    var date = document.getElementById("something").value