Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Changing Equation Question with Javascript isn't saved in Results

  • JanVor
  • JanVor's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago #212700 by JanVor
Hi,

I collect data from an iframe embedded within the survey.
I grab the data and save it in the question text of an Equation type question.
I.e., Question Text:
Code:
<p id="test">....</p>
and help:
Code:
<script>
  window.addEventListener('message', function(event){
    document.getElementById("test").innerHTML = event.data;
  });
</script>

This works in so far that the question text does change to the received data, however, both in a test question in the next question group and in the recorded answers the entry remains "...."

I tried to address the question directly from the script with the expression manager, i.e.,
Code:
<script>
  window.addEventListener('message', function(event){
   {GameData=event.data};
  });
</script>

But that does neither change the question text nor the recorded answer.

I assume I just use the wrong syntax. Does anybody know a solution or workaround?

(LimeSurvey v.3.21.0+191203)

Thank you
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 3 months ago #212709 by tpartner
You cannot dynamically load data into an equation question.

Load it into a short-text question and trigger the keyup event to fire Expression Manager.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: JanVor
The topic has been locked.
  • JanVor
  • JanVor's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago #212717 by JanVor
Thank you!

So I rewrote it to use jQuey so I could utilize past code from here forums.limesurvey.org/forum/can-i-do-thi...nswer-via-javascript .

It does work with in the Question Text Box.
Code:
<script>
  $(window).on('message', function(e) {
    var receivedData = e.originalEvent.data;
    $("#answer{SGQ}").val(receivedData).trigger('keyup');
  });
</script>

However, I cannot have the participants type in (and better not even see) the question. If I set the question to "Always hide this question" it does no longer executes the script. Any way around this?
The topic has been locked.
  • JanVor
  • JanVor's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago #212718 by JanVor
okay, sorry, gotit.
CSS class "hidden" under Display works like a charm.
Thank you again and case closed :)
The following user(s) said Thank You: DenisChenu
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose