Using Javascript with Session Variables?

Options
I've never used session variables before, let alone in Javascript, so forgive me if there's documentation for this somewhere but I've been at this for a while and haven't found it. It's also we're pushing Luminate's survey capabilities farther than we actually should, or that I've mentally skipped something completely here.


Basically we're working on our engagement campaign for the year, and the staff selected to do a personality quiz. The goal is that a person will take a quiz, then the result page will display information about their result. I found this community discussion where someone asked for a similar result; dynamic content on the thank you page based on survey responses, and I tried to implement the response's suggestions by using Javascript to conditionally print a U0 tag, but I am having absolutely 0 luck at getting anything to print on the result page. I've gone through a variety of trials and I'm kind of at the point where I think there either has to be a better way or this is not possible. Has anyone achieved this? Even advice on using Javascript to input session variables or s-tags would be helpful, because I'm pretty sure I'm not understanding the appropriate way to do it.
Tagged:

Comments

  • Javascript has built-in objects that you can use for this - localStorage and sessionStorage. I would check out this page on the W3 site, as it's pretty easy to use and sounds like what you're looking for.

    https://www.w3schools.com/html/html5_webstorage.asp
  • That's a tricky one. In my experience U0 tags don't play well with JS, particularly with conditionals. There are usually workarounds but often they require using undocumented (or sparsely documented) tags. Another idea would be to set the responses as HTML5 sessionStorage using JS, then retrieve them from sessionStorage on the result page before clearing them (especially if any responses could contain personal/sensitive info).


    // Survey page

    jQuery('textarea#1234_56789_0_12345').keyup(function () {

      sessionStorage.setItem('surveyResponse1', jQuery(this).val());

    });


    // Result page

    jQuery('p#surveyResponse1').text(sessionStorage.getItem('surveyResponse1'));

    sessionStorage.removeItem('surveyResponse1');
  • Thank you both so much! This ended up fitting the bill exactly, and according to our analytics there are very very very few site visitors that are using browsers that don't support localStorage and sessionStorage. I've managed to complete the project without any issues. :)

Categories