Open a pdf document by clicking on a specific answer

Compatibilità:IdSurvey 5IdSurvey 6

This javascript can be used to open a pdf document by clicking on a specific answer. The document will open in a new window. This function can be useful in a CATI, for exemple, to open documents with information that interviewers need to read.

NOTE: this javascript is made to open a pdf document when clicking on single select option with code “1”.

Instructions

The first thing we have to do is upload the pdf document in IdSurvey.

Be sure that your platform upload is enabled for pdf format (it's not a standard feature so ask our support if it's the first time you use pdf on surveys).

Go to your question and use the “Insert/edit image” button in the editor to add the pdf into the question. Now go click on the “Source code” button open te source code window, and copy the link of the pdf. This will be used to customize the script.

upload_pdfpdf_link

You can customize your javascript by pasting this link within the javascript, after the “window.open” part, between the ” ” apexes and inside the brackets, replacing the default sample link that you’ll find in the javascript below in bold blue.

Finally, paste the script in the Client script box that you can find in the gearwheel button of the page.

pdf-on-click

The script only works with the option with code 1, as you can see in the javascript below.

<script>
$(":radio").on("change", function(){
var code = $(this).closest("li[data-responsecode]").attr("data-responsecode");
if(code == "1"){
window.open("http://demo.admin.idsurvey.com/img/surveys/example.pdf")
}
});
</script>

 

Leave A Comment?