Have an idea?

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

Can I use java script value into [%SetValue(field_name, val)%]


In Free Format question I need to  share the value across random pages.

As sawtooth is ran before js load, I couldn't assign pass-on-field value from javascript function.

The following value needs to capture from user.
[%SetValue(field_name, value) %]

Or Is there any other work around to set and get value in sawtooth DB from js function.
asked Jul 21, 2018 by Balu (140 points)

1 Answer

0 votes
Unfortunately, it is not possible to run SetValue based on a JavaScript for the reason you've mentioned.  There may be some options for you in working around this problem depending on exactly what you want done with this value.

If you add a hidden free format field to your question, you could have the JavaScript set that hidden field with the value you would have otherwise written to the pass-in field.  Then on a later page, you can either read in this hidden field value or run SetValue to set the pass-in field to the value in the hidden field.

Alternatively, it may be that you don't actually need the pass-in field.  As a simple example, say you want to write a 1 to the pass-in field if the respondent's answer to a numeric question is greater than 4.  Then later you want to use the value in the pass-in field to determine whether to skip a respondent.  In a situation like this, you could instead rework the skip to simply read from the numeric question directly and ignore the pass-in field entirely.

Does this offer some insight?  If you can tell me more about how you want to use the pass-in field, I might be able to offer some more specific help.
answered Jul 23, 2018 by Zachary Platinum Sawtooth Software, Inc. (202,400 points)