Have an idea?

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

JavaScript: hide/show question depend on answer in question above on the same page

Hi everbody

I'm trying to sort out how to use JavaScript in Sawtooth now

The goal: hide one question (q2) before usage, and if, for ex., select question (q1) above on the same page have value=1 then show q2, else q2 is staying hidden

asked Sep 14, 2012 by Ptica (220 points)
edited Sep 14, 2012 by Walter Williams

2 Answers

0 votes
This works in version 7, done the jQuery way. Might be a better way to do this but it uses a 100ms timeout to allow time for the the SSI clickable javascript to run and update the value after you make a selection.

If you have 2 select questions, "q1" and "q2" this will hide q2 unless option 1 is chosen in q1. Make sure q2 is not set to require a response though.

#q2_div {display:none}

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

<script type="text/javascript">


jQuery(document).ready(function($) {
        $("#q1_div .clickable").click(function(){
                if( SSI_GetValue("q1") == 1 ) {$("#q2_div").css('display', 'block'); }

                else {$("#q2_div").css('display', 'none')}

            }, 100);


answered Sep 14, 2012 by Nolan Kaplan Bronze (4,090 points)
0 votes
thank you,  Nolan Kaplan)))

but i realy don't understand if this code works in version 6.
and if it works, where should i put it? because when i put it on Custom JavaScript Verification in Advanced.. there is nothing happened.
and another, as i understand, this code is working only in  100 ms, and if respondent exceed this time it wil not work?

thank you again for explanations)
answered Sep 17, 2012 by Ptica (220 points)
edited Sep 17, 2012 by Ptica
I think it should work in version 6, but I don't have 6 set up to test it out. Would not work in the custom verification area, you'd need to place this either in the header under survey settings, or in the header or footer of q1 or q2. I think it should work if placed in any of those areas.

The 100ms just a small delay before hiding or showing q2, and is not dependent on the respondent, and they should never notice it.