Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Default Value for input type month

Tags:

html

php

Is it possible for me to set the value of input = 'month'using php? I have seen that it is possible using javascript.. but I want to achieve it using php....

I'm trying to set a default value for the input = month.. however the value that I set doesn't take effect..

here's what I did.

when I tried to display it outside the element <?=date('F-Y')?> it displays the date and month just fine..

 <input type="month" value="<?=date('F-Y')?>"  class="form-control per_date_inputs"  name="month"/>
like image 236
Sam Teng Wong Avatar asked Mar 18 '16 07:03

Sam Teng Wong


People also ask

How do you select months in HTML?

The <input type="month"> defines a month and year control. The format is "YYYY-MM".


3 Answers

<input type="month" value="<?=date('Y-m')?>"  class="form-control per_date_inputs"  name="month"/>
like image 147
thxxxx Avatar answered Oct 07 '22 22:10

thxxxx


Instead of

<input type="month" value="<?=date('F-Y')?>"  class="form-control per_date_inputs"  name="month"/>

Use this

<input type="month" value="<?=date('Y-m')?>"  class="form-control per_date_inputs"  name="month"/>
<input type="month" value="2016-03"  class="form-control per_date_inputs"  name="month"/>

input type=month takes "yyyy-mm" format only

like image 20
Grandhi Manikanta Avatar answered Oct 07 '22 23:10

Grandhi Manikanta


If you wanna to make a code for default value for Date or Month; here is the solution:

  • This is for Date:

    <input type="date" name="" id="" value="1982-10-25">
    

    Write the year first then, the month then, the day.

  • This is for Month:

    <input type="month" name="" id="" value="1982-10">
    

    Write the year first then, the month.

like image 29
GXXX Avatar answered Oct 07 '22 22:10

GXXX