0

I have a date picker that when I choose a new date I wish to fire another date picker on another input

Input one:

<input name="pDate" type="text" class="form-control date-with-time-inputs" onchange="changeDate()" id="p_date" placeholder="" value="{{$times['now']}}">

Then I have onchange event

<script>
     function changeDate() {
     const input = document.getElementById('d_date');
     input.select();
     console.log('clicked');
   }
</script>

And then the second input as so

<input name="dDate" type="date" class="form-control date-with-time-inputs" id="d_date" placeholder="" value="{{$times['tomorrow']}}">

The console log fires and the function is working but the 2nd input is not firing up.

Graham Morby
  • 123
  • 2
  • 11

1 Answers1

1

You can't open/click() it from JS(only focus() but that would not help you):

The HTML5 <input> with type='date' will only work with a few browsers. Also, as a programmer you have no control over its appearance or any other aspect (such as showing and hiding it) (Quick FAQs on input type date)

Thus, if you must do this, the HTML5 <input type='date'> tag is not an option. You'll have to use something build in JavaScript such as jQuery UI or Bootstrap date picker.

Found here: https://stackoverflow.com/a/18327043/12753766

Rablin92
  • 61
  • 4