Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Auto submit isn't working

I have a few questions that need to be auto submitted, but the auto submit I've been using seems to not work anymore.

The error I'm getting is
 ciwweb.pl?hid_s=Av8AALWfuzEmH-jaOjRNT518SYAqAAAAhbOICBMs0e0LBntjqEtlsYOsiwcfLdztAhh5Y61QPuXT-d1XQHnY6QIGfXavTWWw:125 Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "default-src 'self' 'unsafe-inline' data:". Note that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.


I've tried two different auto-submit scripts.

The one I've used with success in the past is
<script>
  $(document).ready(function() {
   setTimeout('SSI_SubmitMe()',1);
  });
</script>


and I've also tried this code that I found in the answer to https://legacy.sawtoothsoftware.com/forum/22547/auto-submit-a-page?show=22547#q22547
<body onload="doonload()"> <script language="javascript"> function doonload() { setTimeout('SSI_SubmitMe()',0);  } </script> 


and both are giving me the same error.
asked Sep 3, 2021 by julietcig (160 points)

1 Answer

0 votes
Lighthouse Studio 9.12 introduced some security options that prevent certain scripts from running on a page.  You could modify these settings for this study, but I think the easier option would be to just rewrite your script like this:

<script>
$(document).ready(function() {
    setTimeout(function(){
        SSI_SubmitMe();
    }, 1);
});
</script>


I'm not certain why this script uses a timeout.  If the goal is to allow other custom JavaScript to complete before the auto-submit, we could remove the timeout and just place this script on the page after the other code.  If the goal is to make sure all of Lighthouse's default script completes before the auto-submit, we could use "ssi_ready."  Does this shortened code work for you?

<script>
$(document).on('ssi_ready', function() {
    SSI_SubmitMe();
});
</script>
answered Sep 3, 2021 by Zachary Platinum Sawtooth Software, Inc. (206,100 points)
Shot in the dark, but by chance are you using this script to effectively perform "hidden responses / calculations" on the page before moving the respondent onto the next page?
Hey Zach, I ran into this same issue and I AM using it for some set value scripting before moving the respondent on to the next page.  Was there a different option/solution you had for that?
It's not the end of the world to have such a page in a study, but it comes with some quirks to the respondent experience.  The respondent has to wait longer to get to a meaningful page, they may see some content flashing on their screen for the calculation page, and they may have difficulty backing up in the survey if this special page keeps forcing them forward.

I don't know what calculations you are doing on the page, but I suspect whatever it is could be done on the previous or next page instead, allowing us to remove the calculation page entirely.  For example, if you show the respondent two numerics on the first page and are interested in the sum, you could add this to the very start of the next page:

[% SetValue(SumVariable, NumericQ1 + NumericQ2) %]


Then we could even use the variable on that page with "[% SumVariable %]" so long as that comes later in the page.  Or you could add SumVariable as a third numeric question on the page and set it automatically with this:

<script>
$(document).ready(function(){
    $('#NumericQ1, #NumericQ2').keyup(function(){
        $('#SumVariable').val(SSI_GetValue('NumericQ1') + SSI_GetValue('NumericQ2'));
    });
})
</script>
I see.  What I have done since respondents may see a flash of this screen is add text of 'Submitting response...'

The issue is I'm skipping a question where we ask for the top 3 answers from previously selected if they have 3 or less qualified responses.  I'm then coding those responses with perl and setvalue to the question that was skipped.  The very next question is a loop of the 3 top responses so I don't have an interim question to submit that code on which is why I'm using the auto submit.
So the question is meant to show if there are more than 4 items, but there's no use in showing it if there's 3 or fewer items?  That's a trickier case, but I think we could tackle it by adding a pre-skip to the question that not only checks whether the question should show but also sneakily answers the second question for them.
Basically, yeah.  I have Q7 which is a rating grid.  I'm constructing a list for Q8 for all that are rated 7 or higher.  At Q8 I force them to select their top 3. If there are only 3 or less in that list I'm skipping Q8 (but coding those responses behind the scenes in that auto submit page).  Then Q9 is asked in a loop for each of the 3 items selected at Q8.
Yeah, let's try adding a pre-skip on Q8 with this logic:

Begin Unverified Perl
# Parameters
my $question = 'Q8';
my $list = 'list1';

# Run
my $len = LISTLENGTH($list);
if ($len <= 3) {
    for (my $i = 1; $i <= $len; $i++) {
        SETVALUE($question . '_' . LISTVALUE($list, $i), 1);
    }
    return 1;
}
return 0;
End Unverified


"list1" should be replaced with the name of Q8's list.
I've tried to put this in there and when I click the red checkmark I get a 'Check for Error' message that says: Perl must have content and/or whitespace (e.g., space, new line, or tab) between 'Begin Unverified Perl' and 'End Unverified'. The end blcok 'End Unverified may also be missing.

I
It looks like it is working.  Not sure why it's giving that error when checking logic for that skip though.
Odd.  I'll be sure to pass that along to our QA team to investigate.
...