简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM