5

I'm trying to programmatically trigger the dropdown component (the calendar bit) of an input of type date (similar to clicking the down arrow on the input field). Is this possible? I don't want to use a datepicker library.

HTML:

<input type="date" id="myDatePicker">
<button id="myButton">Click Me</button>

JavaScript/jQuery:

$('#myButton').click(function(){
    //$('#myDatePicker').click();//Doesn't do anything...
    //$('#myDatePicker').blur();//Doesn't do anything...
    //$('#myDatePicker').change();//Doesn't do anything...
    //$('#myDatePicker').focus();//Doesn't do anything...
});

http://jsfiddle.net/joepegler/mvobkjcu/8/

Joe Austin
  • 557
  • 7
  • 24
  • 2
    Related: [Trigger a select form element to show its options (open drop down options list) with Javascript](http://stackoverflow.com/questions/3846735/trigger-a-select-form-element-to-show-its-options-open-drop-down-options-list) – Calvin Scherle Dec 02 '14 at 13:22
  • http://jsfiddle.net/mvobkjcu/13/ – Hackerman Dec 02 '14 at 13:23
  • 1
    Basically according to that question you are not going to be able to achieve this without some plugin or complex workaround. – Calvin Scherle Dec 02 '14 at 13:24

3 Answers3

3

Long story short it would appear that you can't. I used a datepicker instead.

Joe Austin
  • 557
  • 7
  • 24
2

2022 Update

You can use showPicker()

IE:

$('#myDatePicker').showPicker()
jamesdlivesinatree
  • 1,016
  • 3
  • 11
  • 36
-1

Check this out, (achieved this using plugin)

http://jsfiddle.net/pandiyancool/v6zpbmao/

    $(document).ready(function() {
            $("#myDatePicker").datepicker({
                showOn: 'button',
                buttonText: 'Click me',
                dateFormat: 'dd/mm/yy',
                constrainInput: true
            });

            $(".ui-datepicker-trigger").mouseover(function() {
                $(this).css('cursor', 'pointer');
            });

        });
Pandiyan Cool
  • 6,381
  • 8
  • 51
  • 87