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/

3

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

2022 Update

You can use showPicker()

IE:

$('#myDatePicker').showPicker()

Comments

-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');
            });

        });

1 Comment

Per the OP: "I don't want to use a datepicker library..."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.