Skip to main content
code to snippet
Source Link
GrafiCode
  • 3.4k
  • 3
  • 28
  • 32

I am trying to follow the below code to implement addition of days to datepicker

[https://jsfiddle.net/up82wt76/][1]

Below is the code I implemented in Visual Studio 2022

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DateDemo._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script type="text/javascript">
    $('.pickupDate').datepicker();
    $('.dropoffDate').datepicker();

    $('.pickupDate').change(function () {
        var date2 = $('.pickupDate').datepicker('getDate', '+1d');
        //date2.setDate(date2.getDate()+1); 
        $('.dropoffDate').datepicker('setDate', date2.getDate() + 1);
    });
</script>

<div>
    <br />
    <br />
    <input type="text" class="pickupDate" />
    <input type="text" class="dropoffDate" />
</div>
</asp:Content>

It is a straight copy. Why it does not work?

Any help would be greatly appreciated.

$('.pickupDate').datepicker();
$('.dropoffDate').datepicker();

$('.pickupDate').change(function() {
  var date2 = $('.pickupDate').datepicker('getDate', '+1d');
  //date2.setDate(date2.getDate()+1); 
  $('.dropoffDate').datepicker('setDate', date2.getDate() + 1);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

<div>
  <br />
  <br />
  <input type="text" class="pickupDate" />
  <input type="text" class="dropoffDate" />
</div>

I am trying to follow the below code to implement addition of days to datepicker

[https://jsfiddle.net/up82wt76/][1]

Below is the code I implemented in Visual Studio 2022

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DateDemo._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script type="text/javascript">
    $('.pickupDate').datepicker();
    $('.dropoffDate').datepicker();

    $('.pickupDate').change(function () {
        var date2 = $('.pickupDate').datepicker('getDate', '+1d');
        //date2.setDate(date2.getDate()+1); 
        $('.dropoffDate').datepicker('setDate', date2.getDate() + 1);
    });
</script>

<div>
    <br />
    <br />
    <input type="text" class="pickupDate" />
    <input type="text" class="dropoffDate" />
</div>
</asp:Content>

It is a straight copy. Why it does not work?

Any help would be greatly appreciated.

I am trying to follow the below code to implement addition of days to datepicker

[https://jsfiddle.net/up82wt76/][1]

Below is the code I implemented in Visual Studio 2022

It is a straight copy. Why it does not work?

Any help would be greatly appreciated.

$('.pickupDate').datepicker();
$('.dropoffDate').datepicker();

$('.pickupDate').change(function() {
  var date2 = $('.pickupDate').datepicker('getDate', '+1d');
  //date2.setDate(date2.getDate()+1); 
  $('.dropoffDate').datepicker('setDate', date2.getDate() + 1);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

<div>
  <br />
  <br />
  <input type="text" class="pickupDate" />
  <input type="text" class="dropoffDate" />
</div>

Source Link
CPK_2011
  • 1.1k
  • 3
  • 24
  • 65

datepicker does not work even after following the same script

I am trying to follow the below code to implement addition of days to datepicker

[https://jsfiddle.net/up82wt76/][1]

Below is the code I implemented in Visual Studio 2022

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DateDemo._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script type="text/javascript">
    $('.pickupDate').datepicker();
    $('.dropoffDate').datepicker();

    $('.pickupDate').change(function () {
        var date2 = $('.pickupDate').datepicker('getDate', '+1d');
        //date2.setDate(date2.getDate()+1); 
        $('.dropoffDate').datepicker('setDate', date2.getDate() + 1);
    });
</script>

<div>
    <br />
    <br />
    <input type="text" class="pickupDate" />
    <input type="text" class="dropoffDate" />
</div>
</asp:Content>

It is a straight copy. Why it does not work?

Any help would be greatly appreciated.