Question T20837
Visible to All Users

Custom Thank You Message computer from survey answers

created 2 months ago

Hi Survey JS Devs,
I'm making an anonymous form that computes an adjustment to a base rate as a sliding scale implementation.
The code is on Codepen here.
I compute some values and create some text to show on the thank you page, with variable completeText. Based on the example NPS Survey Question I made an update of the survey.completeText within the survey.onComplete callback. However, I find that the survey just freezes after clicking the complete button. The math and JS Indexing used to make the completeText didn't seem possible with an expression, so I just did it with vanilla JS.
How can I go about getting the thank you text to update when the user clicks the Complete button?

Answers approved by surveyjs Support

created 2 months ago (modified 2 months ago)

Hello,
Please use the survey.onProcessHtml function to update a Thank You message for your survey.

JavaScript
survey.onProcessHtml.add((sender, options) => { if(options.reason != "completed") return; let data = sender.data; let k = Object.keys(data); let has_br = Boolean(data.base_rate); let rate; //... options.html = "Your adjusted rate is: " + roundCent(rate);

Consider the updated demo: View Demo.

Let me know if you require further assistance.

    Comments (1)
    SH SH
    Stephen Holsenbeck 2 months ago

      Using the onProcessHtml.add callback appears to work, though slightly differently than anticipated. I modified the sender.options.html value and it worked. The Codepen has been updated accordingly. Thank you @Jane! This is going to be used for a non-profit, non-commercially, is there any way to donate a one-off via Ko-fi or the like?