The start date and end date on the Ajax calendar extender have a difference of 60 days

Currently, I am utilizing two AJAX calendar extenders for my project.

The first one is for the Start Date and the second one is for the End Date.

My requirement is that the end date should always be 60 days ahead of the start date.

The date format from the calendar extender is set as dd-MMM-yyyy (e.g. 08-May-2014).

Here is the code snippet:

<div>
    <asp:TextBox ID="EFF_START_DATEDVTextBox" runat="server" onchange="javascript:EndDateTimeEndDate();" Width="100px" CssClass="txtbox"></asp:TextBox>
    <ajax:CalendarExtender ID="EFF_START_DATEDVCalendarExtender" runat="server" TargetControlID="EFF_START_DATEDVTextBox" Format="dd-MMM-yyyy">

<div>
    <asp:TextBox ID="EFF_END_DATEDVTextBox" onchange="javascript:EndDateTimeEndDate();" runat="server" Width="100px" CssClass="txtbox"></asp:TextBox>
    <ajax:CalendarExtender ID="EFF_END_DATEDVCalendarExtender" runat="server" TargetControlID="EFF_END_DATEDVTextBox" Format="dd-MMM-yyyy">                                                           </ajax:CalendarExtender>
</div>

For example, when a user selects a start date, the end date should automatically be set to 60 days after that, and vice versa.

I attempted to implement this functionality but faced issues with converting the date time properly. Here's the relevant JavaScript function:

function EndDateTimeEndDate() {

        var datestart = new Date(document.getElementById('<%=EFF_START_DATEDVTextBox.ClientID %>').value);
        var dateEnd = new Date(document.getElementById('<%=EFF_END_DATEDVTextBox.ClientID %>').value);
        alert(datestart);
        document.getElementById('<%=EFF_START_DATEDVTextBox.ClientID %>').value = datestart + 60;
}

Answer №1

Give this a try...

document.getElementById('<%=STARTING_DATE.ClientID %>').value = datestart.getDate() - 60;

UPDATE:

    var startdate = new Date(document.getElementById('<%=STARTING_DATE.ClientID %>').value);
    var newDate= new Date();
    newDate.setDate(startdate .getDate() + 60);
    alert(newDate);

Answer №2

Providing the Solution

function CalculateNewEndDate() 
                { 
                        var startDate = document.getElementById('<%=EFF_START_DATEDVTextBox.ClientID %>').value
                        var arrstartdate = startDate.split('-');
                        var newdate = arrstartdate[0] + ' ' + arrstartdate[1] + ' ' + arrstartdate[2] 
                        var actualDate = new Date(newdate); // convert to actual date
                        var newDate = new Date(actualDate.getFullYear(), actualDate.getMonth(), actualDate.getDate() + 60); // create new increased date 
                        // now extract the bits required to form the text version of the new date..
                        var newDateString = ("0" + newDate.getDate()).substr(-2) + '-' + newDate.toDateString().substr(4, 3) + '-' + newDate.getFullYear();
                        var charstr = newDateString.split('-')
                        if (charstr[0].length == 3) 
                        {
                              document.getElementById('<%=EFF_END_DATEDVTextBox.ClientID %>').value = newDateString.substr(1)
                        }
                        else 
                        {
                             document.getElementById('<%=EFF_END_DATEDVTextBox.ClientID %>').value = newDateString 
                        } 
                }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Insert a span element before an HTML input using JavaScript

On my webpage, there is an html input inside a div. Here is what it looks like: <input type="text" class="form-control" placeholder="Barcode" role="barcode"> Using JavaScript only, I am trying to add the following code into the DOM above it: <s ...

A Guide to Triggering a Method Upon Component Change in Angular

When working with Angular, Components have an ngOnInit() method. I am looking for the opposite of this method. Is there a method that gets called when the component is closed? Is there a way to detect in the TypeScript file if the component is being clo ...

What are the methods for choosing various boxes using the UP/DOWN/RIGHT/LEFT arrow keys?

This code snippet displays a 3x3 matrix where boxes can be hovered over and selected. The goal is to navigate around with keys and select boxes using ENTER. Can anyone provide guidance on how to achieve this functionality? <link rel="stylesheet" href ...

Having trouble triggering a click event with JQuery

I have a hidden link for downloading Audio Files that I want the user to access using a button. However, I am having trouble triggering the click event. Below is the HTML code: <a class="APopupDown" data-icon="home" id="DownloadFile" href="http://yaho ...

Comparing Ajax methods: Which one reigns supreme?

I am seeking advice on the best approach to handle a series of Ajax insert, update, and delete operations. Which method is more effective? Creating individual methods for each function (e.g., delete_foo, insert_foo, update_foo, delete_bar, insert_bar, ...

Error in jQuery submenu positioning issue

I am attempting to design a menu that opens when the parent element is clicked and closes when the mouse leaves the previously opened one. It should operate from left to right. Here is an example: <ul class="menuFirst"> <li><im ...

Is using JQuery recommended for implementing onclick and onchange events?

Hello there, I'm completely new to the world of jQuery and currently facing a bit of confusion. Here's my dilemma: should I be utilizing jQuery with the onclick event or the onchange event for an element using something like this: $(selector).som ...

Activate the places_changed event in Google Maps by clicking the submit button

I would like to activate my placed_changed function when a submit button is clicked. Here's what I have so far: I've set up a searchbox using google.maps.places.SearchBox, and when I press enter while the search box is in focus, it triggers the e ...

What is the best method for merging multiple Files (as File[]) into a single Blob?

Is it possible to send a POST request with a form-data body using Postman, along with the following key-value pairs? https://i.sstatic.net/VC2LYMkt.png When attempting to include multiple files, designated as File[], within a single Blob (as shown in the ...

The initial row's Id will be used as the Id for all subsequent rows within a JSON object

After dragging a tr in a table and confirming by clicking a button, I need the order list to be updated in the database. To achieve this, I created a JSON object where I intend to save the ids and their corresponding new orders. The issue I am facing is t ...

Exploring the possibilities of JQuery for smoothly transitioning to internal link destinations?

As a newcomer to JQuery, I have implemented internal links on my website and have a question. Is there a way to create a smooth 'slide down' effect when a user clicks on an internal anchored link text to navigate to the link destination? < ...

Retrieve a true value by using either Array.some or _.some

I am looking to retrieve a truthy value from the array.Some other than "true", This is my approach: let category; arduair.aqi_ranges[pollutant].some((item,index)=> { let min = item.range[0]; let max = item.range[1]; if (_.inRange(c,min,max)){ ...

Is there a way to implement a local gltf loader in three.js to display on a GitHub server within my repository?

Every time I run code on my VS app, it works perfectly fine. However, when I try running it on GitHub, it shows an error 404 and gets aborted. I came across some documentation regarding this issue, but I'm having trouble understanding it. Check out ...

Issue encountered when trying to reach breakpoints within JavaScript libraries using DevTools

When attempting to debug the JavaScript libraries, specifically the KendoUI source file, in Chrome DevTools, I encountered an issue where breakpoints were not being hit despite the code executing. I placed breakpoints in both the minified and prettified fi ...

Employ JavaScript regular expressions to extract all the text values from VBA code

Looking to utilize JavaScript regex in order to extract all string values from VBA code. For instance: If cmd = "History Report" Then Range("D2").Formula = "=TEXT(""" & createDate & """,""" & Replace(subtitleFormat, """", """""") & " ...

Submitting a form using ajax to send form data to php without reloading the page

Could anyone please help me figure out why my code is not functioning properly? I am trying to send form data to PHP using the post method, but my PHP script is not receiving any requests. Below is the code snippet for my signup form located in signupmodal ...

Is it feasible to customize the appearance of native scrollbars in GWT without the need for custom scrollbar definitions or the use of ScrollPanel or CustomScrollPanel?

After encountering an issue with a page jumping due to the appearance of a vertical scroll bar, I have decided to always display the scroll bar by applying html { overflow-y: scroll !important; }, instead of using a script to monitor and adjust window/docu ...

Attempting to add an element to an array results in an endless cycle

Here is a jsfiddle example showcasing the issue, but proceed with caution as it contains an infinite loop that can cause the browser tab to slow down and eventually freeze when the console is opened: https://jsfiddle.net/evx1j6yf/1/ Array Data: days: [ ...

Acquire JSON data structures using Node.js

I've been struggling to find a solution using just keywords - endless scrolling, yet all I can find are tutorials on getting data from JSON structure, rather than getting data structure from JSON. If you're unsure what my end goal is, here are s ...

What could be causing the three.PointLightHelper to fail in my script?

I am encountering an issue with the line of code scene.add(new THREE.PointLightHelper(bluePoint, 3)); in my code snippet below: var bluePoint = new THREE.PointLight(0x0033ff, 100, 500); bluePoint.position.set( 500, -500, 25 ); scene.addLight(bluePoint); s ...