Chris Ray Chris Ray - 1 year ago 617
HTML Question

Using a Javascript Date Selector in Qualtrics survey - carry date to the survey field

I'm trying to input a date selector tool so that a survey respondent can input a date by clicking on the field, a calendar will pop up, they can select the date, and the date will be inputted to the Qualtrics question text box.

Qualtrics has their own calendar tool available, but the issue is that the calendar is always visible. I only want the calendar to be visible when they either click the text box itself or a calendar icon (either would be fine). Here's the Qualtrics code:

Enter a date:
<link href="" rel="stylesheet" type="text/css" /> <script type="text/javascript" src=""></script> <script type="text/javascript" src=""></script> <script>
Qualtrics.SurveyEngine.addOnload(function ()
var qid = this.questionId;
var calid = qid + '_cal';
var y = QBuilder('div');
var d = QBuilder('div',{className:'yui-skin-sam'},[
QBuilder('div', {id:calid}),

var c = this.questionContainer;
c = $(c).down('.QuestionText');
var cal1 = new YAHOO.widget.Calendar(calid);
var input = $('QR~' + qid);
$(input).setStyle({marginTop: '20px',width: '150px'});
var p =$(input).up();
var x = QBuilder('div');
var date = dates[0][0];
if (date[1] < 10)
date[1] = '0' + date[1];
if (date[2] < 10)
date[2] = '0' + date[2];
input.value = date[1] +'-'+date[2]+'-'+date[0];

Here's the calendar tool that I'd like to use, but I can't figure out how to get the date to feed into the Qualtrics field text box.

<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src=""></script>
<script src=""></script>
$( function() {
$( "#datepicker" ).datepicker();
} );

<p>Date: <input type="text" id="datepicker"></p>


Answer Source

Your problem is that in Qualtrics $ refers to prototypejs, not jQuery. So, you need to do something like:

$j = jQuery.noconflict();
$j( function() {
    $j( "#datepicker" ).datepicker();
} );

However, that may not work if the datepicker code is itself using $ to refer to jQuery.

I've used successfully with Qualtrics.

EDIT: To implement datepickr in Quatrics:

  1. Add datepickr script to Qualtrics header (you can upload the file to Qualtrics then get the url of the file to add to the header in a script tag)
  2. Add datepickr CSS to Qualtrics custom CSS
  3. Add JavaScript to your question to add datepickr to an input element (e.g., datepickr($(this.questionId).down('.InputText')), {dateFormat: 'm/d/Y'});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download