Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Show data from file upload question in other questions

  • oledole
  • oledole's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 5 months ago #190251 by oledole
Hello.

I've an upload type question where the user uploads their files and can add an title or comment to it. This works as expected.

However I want to present parts of the data in a new question later on, such as its filename. But using something like {UploadQuestionCode} show what looks like an array of the different data (title, comment, name, filename etc).

How can I select to show only certain parts of this data to show instead of the whole "array"?

I've tried using what I can find from here www.limesurvey.org/es/comunidad/foros/ca...-subsequent-question but this doesn't work for me.


For example adding this:
Code:
function displayUploadFile(uploadFile) {
    document.write('<p>test</p>');
}

to my themes custom.js and using:
Code:
<script type="text/javascript">displayUploadFile({uploadQuestionCode})</script>

doesn't show any result. And that is just trying to get any text to show.

Is there anyway to do what I'm trying to do? If possible even without any javascript.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago - 4 years 5 months ago #190259 by tpartner
Expression Manager cannot handle arrays so you'll have to use a combination of HTML elements, Expression Manager and JavaScript.

Disable AJAX in the survey settings and add something like this to the question text where you want to display the upload details. The JavaScript will retrieve the upload question results, parse the array and load the various <span> elements that you have placed in the question text.

Code:
The upload title is: <span class="upload-title"></span><br />
The upload comment is: <span class="upload-comment"></span><br />
The upload filename is: <span class="upload-name"></span>
 
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Retreive the upload question results
    var uploadResults = {Q1};
 
    // Load the span elements
    $('#question{QID} span.upload-title').text(uploadResults[0]['title']);
    $('#question{QID} span.upload-comment').text(uploadResults[0]['comment']);
    $('#question{QID} span.upload-name').text(uploadResults[0]['name']);
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...7141.lss
File Size:15 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 5 months ago by tpartner.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose