Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Why isn't my data being recorded using this code?

I used this code to add the question "When did you make your reservation?" Using this code, the question appears on my survey but it isn't recorded when I go to download data. What do you recommend for next steps?



<input type="text" id="datePicker" placeholder="dd/mm/yyyy">
<input name="FreeFormatQ_Unix" id="FreeFormatQ_Unix" type="hidden" value="">
<input name="FreeFormatQ_Year" id="FreeFormatQ_Year" type="hidden" value="">
<input name="FreeFormatQ_Month" id="FreeFormatQ_Month" type="hidden" value="">
<input name="FreeFormatQ_Day" id="FreeFormatQ_Day" type="hidden" value="">
<input name="FreeFormatQ_ReadableString" id="FreeFormatQ_ReadableString" type="hidden" value="">
 
<script>
$('#datePicker').datepicker({
    onClose: function(){
        var date = $('#datePicker').datepicker('getDate');
         
        // Unix
        $('#FreeFormatQ_Unix').val(date.getTime());
         
        // Y, M, D
        $('#FreeFormatQ_Year').val(date.getFullYear());
        $('#FreeFormatQ_Month').val(date.getMonth() + 1); // months are zero-based
        $('#FreeFormatQ_Day').val(date.getDate());
         
        // Readable string
        $('#FreeFormatQ_ReadableString').val($.datepicker.formatDate('MM d, yy', date));
    }
});
</script>
related to an answer for: Date picker in free format question
asked 2 days ago by Liz S

1 Answer

0 votes
Please try this updated script:

<input type="text" id="datePicker" placeholder="dd/mm/yyyy">
<input name="[% QuestionName() %]_Unix" id="[% QuestionName() %]_Unix" type="hidden" value="">
<input name="[% QuestionName() %]_Year" id="[% QuestionName() %]_Year" type="hidden" value="">
<input name="[% QuestionName() %]_Month" id="[% QuestionName() %]_Month" type="hidden" value="">
<input name="[% QuestionName() %]_Day" id="[% QuestionName() %]_Day" type="hidden" value="">
<input name="[% QuestionName() %]_ReadableString" id="[% QuestionName() %]_ReadableString" type="hidden" value="">
 
<script>
$('#datePicker').datepicker({
    onClose: function(){
        var date = $('#datePicker').datepicker('getDate');
        
        if (date) {
            // Unix
            $('#[% QuestionName() %]_Unix').val(date.getTime() / 1000);
            
            // Y, M, D
            $('#[% QuestionName() %]_Year').val(date.getFullYear());
            $('#[% QuestionName() %]_Month').val(date.getMonth() + 1); // months are zero-based
            $('#[% QuestionName() %]_Day').val(date.getDate());
            
            // Readable string
            $('#[% QuestionName() %]_ReadableString').val($.datepicker.formatDate('MM d, yy', date));
        }
    }
});
</script>


Of course, you'll still need to include "_Unix," "_Year," "_Month," "_Day," and "_ReadableString" hidden variables in your free format question.  The last one absolutely has to be text-type - you could make them all text-type just to be sure.
answered 2 days ago by Zachary Platinum Sawtooth Software, Inc. (129,150 points)
...