Sam Teng Wong
Sam Teng Wong

Reputation: 2439

Set Default Value for input type month

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"/>

Upvotes: 5

Views: 9326

Answers (3)

GXXX
GXXX

Reputation: 21

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.

Upvotes: 2

Grandhi Manikanta
Grandhi Manikanta

Reputation: 81

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

Upvotes: 4

thxxxx
thxxxx

Reputation: 161

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

Upvotes: 10

Related Questions