Click here to Skip to main content
16,006,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a problem with my project ,

I have two datepicker in my project ,


value of the second datepicker in setted auto based on first datepicker ,

example of ,

txt.datepicker value ='07/09/2020'

so txt2.datepicker value is txt.datepicker + 2 month
or '07/11/2020'

how can i solve this?

What I have tried:

this is my code

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
 <div class="box-body">
     <dl class="dl-horizontal">
        <dt style="text-align:left">
               <label for="StartDate">Start Date</label>
                    </dt>
                      <dd style="text-align:left" >
                         <asp:TextBox ID="txtDate" onkeypress="copyText()"  Width="200px" runat="server" ReadOnly="true" Height="34px"></asp:TextBox>
                        </dd>
                             <dt style="text-align:left">
                                 <label for="StartDate">Expired Date</label>
                                 </dt>
                                 <dd style="text-align:left">
                                       <asp:TextBox ID="txtdate2"  ReadOnly="true"  Width="200px" Height="34px" runat="server"></asp:TextBox>
                                    </dd>
         </dl>
         </div>
<script type="text/javascript">
         $(function () {
             $("[id*=txtDate]").datepicker({
                 showOn: 'button',
                 buttonImageOnly: true,
                 buttonImage: '/Images/calendar.png',
             });
             $(".ui-datepicker-trigger").css("margin-bottom", "2px");
         });
</script>
    
    <script type="text/javascript">
            $(function () {
                $("[id*=txtdate2]").datepicker({
                    showOn: 'button',
                    buttonImageOnly: true,
                    buttonImage: '/Images/calendar.png',
                });
                $(".ui-datepicker-trigger").css("margin-bottom", "2px");
            });
</script>
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
	<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="Stylesheet" type="text/css" />

    <script type="text/javascript">
        function copyText() {
        var givenvalue = document.getElementById("<%=txtDate.ClientID%>");
        var displayvalue = document.getElementById("<%=txtdate2.ClientID%>");
        var settedvalue = givenvalue;
        displayvalue.value = settedvalue.value;
    }
</script>


</asp:Content>
Posted
Updated 12-Jul-20 21:42pm

1 solution

Use a JavaScript Date Reference[^] which has methods to manage the values of individual parts.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900