-1

In my javascript code I'm using datepicker, like this:

<script type="text/javascript" language="javascript">
function datepicker(element) {
        element.datepicker({
            showOn: "both",
            buttonImage: "calendar",
            buttonImageOnly: true
        });
    }

and later I'm attaching it to the input with id="startDate":

$(document).ready(function(){
        datepicker($("#startDate"));
    });

it works correctly and fills the startDate input with selected date. But I also have the second input, called endDate - is there a way to handle it within datepicker, so that when user selects startDate, the endDate is populated automatically with a selected date incremented of 2 days?

randomuser1
  • 2,733
  • 6
  • 32
  • 68
  • 1
    Can you add a [mre]? – 0stone0 Dec 08 '22 at 15:57
  • Check this please https://stackoverflow.com/questions/55804024/automatically-changes-end-date-after-start-date-is-picked – ProblemChild Dec 08 '22 at 16:37
  • 1
    Which date picker library and what version? – Yogi Dec 08 '22 at 16:41
  • It looks like you are using the jQuery UI datepicker ([`buttonImage` is an option](https://api.jqueryui.com/datepicker/#option-buttonImage) for that), but you are [initialising it incorrectly](https://jqueryui.com/datepicker/). If you *are* using that datepicker, a basic search like "*jquery ui datepicker set end date*" turns up many answers here already, here's a random example: https://stackoverflow.com/questions/27721133/jquery-datepickers-setting-end-date-from-a-start-date – Don't Panic Dec 12 '22 at 22:08

1 Answers1

0

Try having same class for two inputs and pass the class name instead of id and pass it to datepicker($(".dateField"));

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
SKamban
  • 1
  • 1