<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>article How to perform Dynamic Date Selection with help of JavaScript Event on browser click path synthetic monitor while working with Travel Sites in Troubleshooting</title>
    <link>https://community.dynatrace.com/t5/Troubleshooting/How-to-perform-Dynamic-Date-Selection-with-help-of-JavaScript/ta-p/209315</link>
    <description>&lt;DIV class="s-prose js-post-body"&gt;
&lt;H1&gt;Summary&lt;/H1&gt;
&lt;P&gt;For dates that need to be dynamically selected, for example, always select a date 37 days in the future, some script customization is required. This is often seen on travel-related sites where from and to dates are needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;Solution&amp;nbsp;&lt;/H1&gt;
&lt;P&gt;The following JavaScript code snippet can be modified to perform Dynamic Date Selection in a browser clickpath synthetic monitor.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;var now = new Date();
var today = new Date(now.getFullYear(), (now.getMonth()), now.getDate());
var oneMonthLater = new Date(today.valueOf() + 30*1*24*60*60*1000); //30 days later from the current date
api.info(oneMonthLater); 

var ReturnDate = new Date(today.valueOf() + 37*1*24*60*60*1000);
api.info(ReturnDate); //37 days later from the current date

function monthConverter(month){     switch(month){         case 0: return '01';         case 1: return '02';         case 2: return '03';         case 3: return '04';         case 4: return '05';         case 5: return '06';         case 6: return '07';         case 7: return '08';         case 8: return '09';         case 9: return '10';         case 10: return '11';         case 11: return '12';     } }


var startMonth = monthConverter(oneMonthLater.getMonth());
var startDay = ("0" + oneMonthLater.getDate()).slice(-2);
var startYear = oneMonthLater.getFullYear();
var returnMonth = monthConverter(ReturnDate.getMonth());
var returnDay = ("0" + ReturnDate.getDate()).slice(-2);
var returnYear = ReturnDate.getFullYear();
var departDate = startYear  + "-" + startMonth+ "-" + startDay;  // change the variable order format and delimiter based on your input filed based on your date format for both departDate &amp;amp; returnDate variables. In this example date format is dd-mm-yyyy
var returnDate = returnYear  + "-" + returnMonth + "-" + returnDay; 
api.info(departDate);
api.info(returnDate);
function triggerevent(element) {
    var evt = document.createEvent("MouseEvent");
    var eventType = ["input", "change"];
    for (i = 0; i &amp;lt; eventType.length; i++) {
        evt.initMouseEvent(eventType[i], true, true, window);
        element.dispatchEvent(evt);  } }

var element1 = document.querySelector("#From"); // Replace with From input field JS Path
var element2 = document.querySelector("#To");   // Replace with To input field JS Path
element1.value = departDate;
triggerevent(element1);
element2.value = returnDate;
triggerevent(element2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;Steps to update and use the JavaScript snippet&lt;/H2&gt;
&lt;OL&gt;
&lt;LI&gt;Go to the relevant page on Chrome browser&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Right click on the From &amp;amp; To Date input elements which you want to perform the dynamic date selection on the page-&amp;gt; Inspect the element which will open the developer tools&lt;/P&gt;
&lt;DIV id="tinyMceEditorMareeswaran_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image1.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11005i0EEA3FBCC8EA52AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="image1.png" alt="image1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Right click on the element on the Web developer tools - &amp;gt; Copy - &amp;gt; Copy JS path of both From &amp;amp; To Date input elements&lt;/P&gt;
&lt;DIV id="tinyMceEditorMareeswaran_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image2.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11006i2D588F2A913F9139/image-size/large?v=v2&amp;amp;px=999" role="button" title="image2.png" alt="image2.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Paste the JS path on the below element1 &amp;amp; element2 value and add this JavaScript code into the JavaScript Event of your Browser click path monitor which will enter the Dynamic Date on From &amp;amp; To input fields as shown in the below image,&lt;/P&gt;
&lt;DIV id="tinyMceEditorMareeswaran_2" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image4.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11007iAE71D5049D1F6853/image-size/large?v=v2&amp;amp;px=999" role="button" title="image4.png" alt="image4.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Note:- Change the departDate and returnDate variable assigned order format and delimiter based on your input filed date format. In this example date format is dd-mm-yyyy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1 id="toc-hId--526228148"&gt;What's Next&lt;/H1&gt;
&lt;P&gt;If none of the previous steps resolved the issue, open a chat and a link to the monitor and this article.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;You can find further troubleshooting tips for Synthetic in the&amp;nbsp;&lt;A class="" href="https://community.dynatrace.com/t5/Troubleshooting/Synthetic-Troubleshooting-Map/ta-p/250426" target="_blank" rel="noopener"&gt;Synthetic Troubleshooting Map&lt;/A&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Fri, 19 Sep 2025 15:02:51 GMT</pubDate>
    <dc:creator>Mareeswaran</dc:creator>
    <dc:date>2025-09-19T15:02:51Z</dc:date>
    <item>
      <title>How to perform Dynamic Date Selection with help of JavaScript Event on browser click path synthetic monitor while working with Travel Sites</title>
      <link>https://community.dynatrace.com/t5/Troubleshooting/How-to-perform-Dynamic-Date-Selection-with-help-of-JavaScript/ta-p/209315</link>
      <description>&lt;DIV class="s-prose js-post-body"&gt;
&lt;H1&gt;Summary&lt;/H1&gt;
&lt;P&gt;For dates that need to be dynamically selected, for example, always select a date 37 days in the future, some script customization is required. This is often seen on travel-related sites where from and to dates are needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;Solution&amp;nbsp;&lt;/H1&gt;
&lt;P&gt;The following JavaScript code snippet can be modified to perform Dynamic Date Selection in a browser clickpath synthetic monitor.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;var now = new Date();
var today = new Date(now.getFullYear(), (now.getMonth()), now.getDate());
var oneMonthLater = new Date(today.valueOf() + 30*1*24*60*60*1000); //30 days later from the current date
api.info(oneMonthLater); 

var ReturnDate = new Date(today.valueOf() + 37*1*24*60*60*1000);
api.info(ReturnDate); //37 days later from the current date

function monthConverter(month){     switch(month){         case 0: return '01';         case 1: return '02';         case 2: return '03';         case 3: return '04';         case 4: return '05';         case 5: return '06';         case 6: return '07';         case 7: return '08';         case 8: return '09';         case 9: return '10';         case 10: return '11';         case 11: return '12';     } }


var startMonth = monthConverter(oneMonthLater.getMonth());
var startDay = ("0" + oneMonthLater.getDate()).slice(-2);
var startYear = oneMonthLater.getFullYear();
var returnMonth = monthConverter(ReturnDate.getMonth());
var returnDay = ("0" + ReturnDate.getDate()).slice(-2);
var returnYear = ReturnDate.getFullYear();
var departDate = startYear  + "-" + startMonth+ "-" + startDay;  // change the variable order format and delimiter based on your input filed based on your date format for both departDate &amp;amp; returnDate variables. In this example date format is dd-mm-yyyy
var returnDate = returnYear  + "-" + returnMonth + "-" + returnDay; 
api.info(departDate);
api.info(returnDate);
function triggerevent(element) {
    var evt = document.createEvent("MouseEvent");
    var eventType = ["input", "change"];
    for (i = 0; i &amp;lt; eventType.length; i++) {
        evt.initMouseEvent(eventType[i], true, true, window);
        element.dispatchEvent(evt);  } }

var element1 = document.querySelector("#From"); // Replace with From input field JS Path
var element2 = document.querySelector("#To");   // Replace with To input field JS Path
element1.value = departDate;
triggerevent(element1);
element2.value = returnDate;
triggerevent(element2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;Steps to update and use the JavaScript snippet&lt;/H2&gt;
&lt;OL&gt;
&lt;LI&gt;Go to the relevant page on Chrome browser&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Right click on the From &amp;amp; To Date input elements which you want to perform the dynamic date selection on the page-&amp;gt; Inspect the element which will open the developer tools&lt;/P&gt;
&lt;DIV id="tinyMceEditorMareeswaran_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image1.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11005i0EEA3FBCC8EA52AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="image1.png" alt="image1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Right click on the element on the Web developer tools - &amp;gt; Copy - &amp;gt; Copy JS path of both From &amp;amp; To Date input elements&lt;/P&gt;
&lt;DIV id="tinyMceEditorMareeswaran_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image2.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11006i2D588F2A913F9139/image-size/large?v=v2&amp;amp;px=999" role="button" title="image2.png" alt="image2.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Paste the JS path on the below element1 &amp;amp; element2 value and add this JavaScript code into the JavaScript Event of your Browser click path monitor which will enter the Dynamic Date on From &amp;amp; To input fields as shown in the below image,&lt;/P&gt;
&lt;DIV id="tinyMceEditorMareeswaran_2" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image4.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11007iAE71D5049D1F6853/image-size/large?v=v2&amp;amp;px=999" role="button" title="image4.png" alt="image4.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Note:- Change the departDate and returnDate variable assigned order format and delimiter based on your input filed date format. In this example date format is dd-mm-yyyy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1 id="toc-hId--526228148"&gt;What's Next&lt;/H1&gt;
&lt;P&gt;If none of the previous steps resolved the issue, open a chat and a link to the monitor and this article.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;You can find further troubleshooting tips for Synthetic in the&amp;nbsp;&lt;A class="" href="https://community.dynatrace.com/t5/Troubleshooting/Synthetic-Troubleshooting-Map/ta-p/250426" target="_blank" rel="noopener"&gt;Synthetic Troubleshooting Map&lt;/A&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 19 Sep 2025 15:02:51 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Troubleshooting/How-to-perform-Dynamic-Date-Selection-with-help-of-JavaScript/ta-p/209315</guid>
      <dc:creator>Mareeswaran</dc:creator>
      <dc:date>2025-09-19T15:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform Dynamic Date Selection with help of JavaScript Event on browser click path synthetic monitor while working with</title>
      <link>https://community.dynatrace.com/t5/Troubleshooting/How-to-perform-Dynamic-Date-Selection-with-help-of-JavaScript/tac-p/212103#M192</link>
      <description>&lt;P&gt;Thank you for sharing this! I'm sure it will help out many community members.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 19:05:47 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Troubleshooting/How-to-perform-Dynamic-Date-Selection-with-help-of-JavaScript/tac-p/212103#M192</guid>
      <dc:creator>ChadTurner</dc:creator>
      <dc:date>2023-05-12T19:05:47Z</dc:date>
    </item>
  </channel>
</rss>

