Have an idea?

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

custom error message in skip logic

How to display and alert box/error message in skip logic?
Basically I wanted display an error message before skip to the specified question, is it possible?
asked Jun 19, 2019 by raaamuz (360 points)
Skip logic is ran on the survey's server, so it cannot be used to show a message to the respondent.  In order to achieve what you want, you'll likely need to involve some JavaScript.  Can you expound on the behavior you are after?  Does the alert show up then the page skips after the respondent clicks on the alert?
would it be possible to use javascript with in perl script?
like the below syntax is possible?

 [% <script>alert("error")</script>%]
No, code on the server cannot fire an alert in the browser.  The closest you can get to that is by having Sawtooth Script return a string with script in it that then gets ran in the browser, like this:

[% Begin Unverified Perl
return '<script>alert("error");</script>';
End Unverified %]

But that can only be done in a question text or similar part of the questionnaire because the result of Sawtooth Script on those pages is sent to the respondent's browser.  Skip logic does not do that.
Thanks, please confirm me one more thing, is it possible to include a value of a question? like alert("error"+VALUE(Q1))?
Sure.  In the same way that Sawtooth Script can be used to print values to the webpage, it can also be used to print values into JavaScript code.  You will still need to include the "[%" and "%]".  Here's an example:

alert('Your response to the first question was [% Q1 %]');
That only applies if Q1 is on an earlier page of the questionnaire.  If you want the alert to include the response to a question on the current page, you will need to use JavaScript like SSI_GetValue rather than Sawtooth Script.

Your solution to the original question

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.