Javascript to force upload file on click next | XM Community
Question

Javascript to force upload file on click next

  • 7 August 2020
  • 2 replies
  • 41 views

Userlevel 1
Badge +1

Hi,
I have a survey in which I implement an upload file button using html and javascript (I'm not using the inherent Qualtrics upload file question because I need to upload big files and there's a size limitation in the Qualtrics question). The files are successfuly uploaded to my AWS S3 bucket.
My question regards the validation of the file upload before moving forward to the next page - how can I validate (and throw an error if not) that the user uploaded the file? I tried the following, but after throwing the error it moves forward anyway (and I want to stay in this page, until no error is thrown). Thanks!
My JS code:
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
let file = $("#file").prop('files')[0];  
if (!file) {
alert("Please upload your video file.");
}
});


2 replies

Userlevel 7
Badge +22

Create a duplicate Next button and on click of it validate if the file was uploaded or not. If yes, then click the real next button using js code else show the alert.

Userlevel 1
Badge +1

Thanks rondev !
Do you have a sample code for such button, so that it'll be as similar as possible to the Qualtrics real next button? I don't have a lot of experience with html coding...
Thanks!

Leave a Reply