More about dates and JavaScript | XM Community
Skip to main content
Question

More about dates and JavaScript

  • August 8, 2022
  • 2 replies
  • 21 views

Forum|alt.badge.img

Hello again:
I'm making a bit of progress, but am still struggling with the Qualtrics Variable Names.
Here is my updated code:
Qualtrics.SurveyEngine.addOnSubmit(function()
{


      function dateproduce(x) {
  const myArray1 = x.split(".")
  var y1 = myArray1[1];
         var m1 = myArray1[0]-1;
         if(m1==-1) {
  m1 = 12;
  y1 = y1 - 1;
}
      var dt1 = new Date(y1,m1);
  return dt1;
      }
      var st =  "${q://QID3%231/ChoiceTextEntryValue/1/1}";
  console.log(st) 
      let dta1 = dateproduce(st);
      var et =  "${q://QID3%232/ChoiceTextEntryValue/1/1}";
      let dta2 = dateproduce(et);
      if(dta2 < dta1)
  Qualtrics.SurveyEngine.setEmbeddedData('FinalResponse',"incorrect");
      else
  Qualtrics.SurveyEngine.setEmbeddedData('FinalResponse',"correct");



});
```
The FinalResponse is not getting any value.
Any suggestions much appreciated.
Sincerely,
Erin
qual1.png

2 replies

grahulp5
QPN Level 3 ●●●
Forum|alt.badge.img+13
  • QPN Level 3 ●●●
  • October 17, 2022

I'm not sure but did you try consoling these values on ready?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • October 17, 2022

The function name should be addOnPageSubmit(). However, since you aren't a getting any data from the page itself, you might as well use addOnload(). That way you don't have to click Next to see what you've logged to the console.