How to call functions defined in header script? | XM Community
Skip to main content
Hi,



I'm trying to use Qualtrics to create a user study for my thesis research. As you can see from the example preview below, I managed to create interactive maps in each question that the user can interact with.

Example preview



The JS code needed to do this is copied in each question which is not ideal when I need to edit things, etc... I have found that it should be possible to include code in the header field using <script> tags to define global functions that are usable in each question, but when I try to call

`Qualtrics.SurveyEngine.addOnload(function()

{

begin();



});`



in the JS editor I get a reference error that begin() is not defined. I also tried to call begin() from the HTML View but this gives the same result.



How do I properly call functions that are defined in my header?



Thanks!
In your question:

```

Qualtrics.SurveyEngine.addOnload(function() {

begin(this);

});

```



In your header:

```

<script>

function begin(qobj) {

//JS code here

}

</script>

```

Leave a Reply