Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 button to trigger date input on mobile

I have a HTML5 design where I want to be able to use a button to display a date, but I want to use the HTML5 input type="date" to select the date.

Here is my code:

<button type="button" id="btnDate" class="btn btn-primary">
    <span class="glyphicon glyphicon-calendar"></span> <span class="date">27 Jul 2015</span>
</button>
<input type="date" class="hidden" id="tbDate" />

<script type="text/javascript">
    $(document).ready(function() {
        $("#btnDate").click(function () {
            $("#tbDate").focus();
        });
    });             
</script>

I've tried focus() and click() - neither work...any ideas?

like image 844
Matthew Layton Avatar asked Sep 07 '15 09:09

Matthew Layton


People also ask

How do I create a date Button in HTML?

The <input type="date"> defines a date picker. The resulting value includes the year, month, and day.

How can set input type date in mm/dd/yyyy format using HTML?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.

How do I get the input type for a date?

<input type="date"> <input> elements of type="date" create input fields that let the user enter a date, either with a textbox that validates the input or a special date picker interface. The resulting value includes the year, month, and day, but not the time.

Which HTML5 attributes can be used with HTML5 date input type to limit date selection?

The max attribute specifies the maximum value (date) for a date field.


1 Answers

Please browse with your phone.

<label for="dateInput">click button</label>
<input type="date" id="dateInput" />
like image 52
MaxWang Avatar answered Sep 30 '22 18:09

MaxWang