JQuery does not load the calendar in a loop and merge block after the first block | XM Community
Skip to main content
Hello,

I am trying to implement the jQuery datepicker in a loop and merge block. It works fine for the first loop but after that, the calendar does not show up when I click on the text field for entering a date. I notice that this also happens when hitting the back button after selecting a date. Is this an issue with the Qualtrics survey engine or jQuery itself?



Here is the code that I am currently using (credit to @fleb):





```

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title> Datepicker</title>

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

<link rel="stylesheet" href="/resources/demos/style.css">

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script>

$( function() {

$( "#datepicker" ).datepicker({

minDate: '-30',

maxDate: '-1'

});

} );



Qualtrics.SurveyEngine.addOnPageSubmit(function()

{

Qualtrics.SurveyEngine.setEmbeddedData("date${lm://CurrentLoopNumber}", document.getElementById("datepicker").value );



});



</script>

</head>

<body>



Enter a date: <input type="text" id="datepicker">



</body>



```
@JordanP,



Below code should be able to resolve your issue.



Qualtrics.SurveyEngine.addOnUnload(function()

{

/*Place your JavaScript here to run when the page is unloaded*/

jQuery("#ui-datepicker-div").remove();

});

Leave a Reply