Open a PDF document by clicking on a specific answer

Compatibility: IdSurvey 6 IdSurvey 7

By setting this script you will be able 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.

This javascript was created to open a pdf document when clicking on a single select answer option (in this case option with code “1”).

Step 1

First of all, you will have to upload the pdf document on IdSurvey.

Make sure that your platform upload is enabled for pdf format. Since it is not a standard feature please ask our support team if it is the first time you use pdf files on surveys.

Go to the question and use the “Insert/edit image” button in the editor to add the pdf into the question.

Step 2

Now click on the “Source code” button to open the source code window and copy the link of the pdf. You will need this link in order to customize the script.

upload_pdfpdf_link

Step 3

You can customize your javascript by copying this link into the javascript, after the “window.open” part, between the ” ” quotes and inside the brackets, replacing the default sample link that you will find in the javascript below in bold blue. Your link will have to be similar to the following one:

https://demo.admin.idsurvey.com/img/surveys/IdSurvey-Overview.pdf

Step 4

Finally, copy the script in the “Client script” box that you will 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?