Javascript to force upload file on click next | XM Community
Skip to main content

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.");
}
});

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.


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