I'm not able to change embedded field from a keyup event listener. | XM Community
Question

I'm not able to change embedded field from a keyup event listener.

  • 17 October 2019
  • 4 replies
  • 49 views

Userlevel 5
Badge +6
  • Level 3 ●●●
  • 197 replies
Hi all,
I'd like to create a function which would put the number of times printscreen key was pressed into the embedded data.
However, I found out that I'm not able to change the value of the embedded field from my event listener. I tried to change HTML of a given element from my function instead and it didn't work neither. There are no errors in the console. Both lines of the work in case they're outside the event listener.
Would anyone have some ideas how to solve this?

Qualtrics.SurveyEngine.addOnload(function()
{
var that = this;
var id = that.questionId;

jQuery("#" + id + " .QuestionText").append('<div id = "my_n">my_n</div>');


jQuery(window).focus();

jQuery(document).keyup(function(e) {
if (e.keyCode == 44)

{
Qualtrics.SurveyEngine.setEmbeddedData('print_screen', "TEST");
jQuery("#my_n").html("TEST");

}
})

});

4 replies

Userlevel 3
Badge +9
You can only set embedded data onPageSubmit sadly. This is not documented very well but I learned about it through others here on the forum.
Userlevel 5
Badge +6
> @Pete_L said:
> You can only set embedded data onPageSubmit sadly. This is not documented very well but I learned about it through others here on the forum.

Thank you very much for your answer. However, I don't think you're right. I set embedded data in `OnReady` and `OnLoad` in many other scripts and I never had a problem (before I needed to do do it from the `keyup`).
Right now I have tested to set embedded data from all 4 possible functions (see the script below) and everything except OnUnload worked. Would you be able to put here some links on discussions which leaded you to your answer?

Qualtrics.SurveyEngine.addOnload(function()
{
Qualtrics.SurveyEngine.setEmbeddedData('load', true);

});

Qualtrics.SurveyEngine.addOnReady(function()
{
Qualtrics.SurveyEngine.setEmbeddedData('ready', true);

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
Qualtrics.SurveyEngine.setEmbeddedData('unload', true);

});

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
Qualtrics.SurveyEngine.setEmbeddedData('submit', true);

});
Userlevel 3
Badge +9
If that's the case then that's wonderful news - I will look for the older threads.

How are you confirming it's being set on those actions? Are you piping the results of all of them on the same screen where they all take place?
Userlevel 5
Badge +6
> @Pete_L said:
> If that's the case then that's wonderful news - I will look for the older threads.
>
> How are you confirming it's being set on those actions? Are you piping the results of all of them on the same screen where they all take place?

I looked at data (Data&analylis). The case is that I can send data from OnLoad or OnRady, but not in the case that it is also inside a `keyup` event listener...

Leave a Reply