Join this month's Badge of the Month 💬 discussion about X4 to earn your exclusive badge! | Earn Badge >
UPDATED // COMMUNITY DOWNTIME NOTICE New Community Platform 🚨 Read our updated post to learn about expected Community downtime | CLICK HERE >

Date Range Picker (JavaScript)

Guide Michigan
edited July 2021 in Custom Code


I am trying to add a calendar that allows a customer to choose a range of dates. I found one that was developed by Andrew Petrus using JavaScript ( It works fine except when I select the dates, the calendar/text box disappears on the computer preview, but not the Smartphone preview. Has anyone successfully added a date range calendar either using Andrew's method or another? Thanks in advance for any help/leads.


Best Answers

  • TomG
    TomG Raleigh, NC Level 8 ●●●●●●●●
    Accepted Answer

    Check out flatpickr. It does ranges, is easy to integrate with Qualtrics, and much lighter.

  • TomG
    TomG Raleigh, NC Level 8 ●●●●●●●●
    Accepted Answer

    @esegui said:
    coding is not my forte. In the look and feel advanced, I inserted this for jquery and flatpickr
    var $j = jQuery.noConflict();

    then in the JS oiption in the question

    obviously, I'm doing something worng
    Thanks for your help

    Yes, you are. No need to load jQuery (Qualtrics already loads it), so your look & feel header is just:

    <link href="" rel="stylesheet" />
    <script src=""></script>

    Then in your question, you need to attach flatpickr to a text input:

    jQuery("#"+this.questionId+" .InputText").flatpickr();
  • cawen
    Accepted Answer

    I have a simple but powerful improvement to the calendar code that's described here. Basically, qualtrics now provides a calendar picker example question that you can import via Qualtrics Library > Survey Questions > Demographics > Calendar & Date > "Enter a date:". See video:

    This however provides a very bulky calendar that takes up alot of room. What i've done is modified the code so that the calendar is hidden and only toggles when you click on the input field and after selecting the date it will again toggle hide.

    Simply add the following code to the html view of your input text question type.

    Enter date here (MM-DD-YYYY):<link rel="stylesheet" type="text/css" href=""> 
    <script type="text/javascript" src=""></script> 
    <script type="text/javascript" src=""></script>

    Then in add the following Javascript to your question within Qualtrics.SurveyEngine.addOnload(function(){

        /*Place your JavaScript here to run when the page loads*/
        let qid = this.questionId;
        let qContainer = this.questionContainer;
        //===Creates Calendar===
        let calOuter = QBuilder('div');
        let calid = qid+'_cal';
        let calender = QBuilder('div',{className:'yui-skin-sam'},[QBuilder('div', {id:calid}), calOuter]);
        qContainer = $(qContainer).down('.QuestionText');
        let yahWidget = new YAHOO.widget.Calendar(calid); 
        //===Creates Input Field===
        let inputField = $('QR~' + qid);
        $(inputField).setStyle({marginTop: '20px',width: '150px'});
        let inputContainer =$(inputField).up();
        let inputDiv = QBuilder('div');
        //===Toggles Show Calendar===
        inputField.addEventListener("click", function() {
        //===Select Date and Toggles Hide Calendar===
            let date = dates[0][0];
            if (date[1] < 10) {date[1] = '0' + date[1];};
            if (date[2] < 10) {date[2] = '0' + date[2];};
            inputField.value = date[1] +'-'+date[2]+'-'+date[0];