Have an idea?

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

Grey out text box using Javascript

I have a freeformat question set out with three text boxes and then a checkbox for don't know. I would like the textboxes to grey out and the words "Don't know" to appear in the first text box if the respondent clicks the "Don't know" option. I really have no javascript experience, so am a bit lost on how to go about this.
asked Dec 12, 2011 by sawtoothuser (150 points)

1 Answer

0 votes
 
Best answer
Hello,

with the graphical buttons in SSI7 turned off in options the code below will do what you want. the freeformat questions name is assumed to be ff1 and the 3 textboxes are named ff1_text1, ff1_text2 and ff1_text3 (with require response option unchecked); the checkbox variable is set as checkbox with one option and it is named ff1_dk
<input name="ff1_text1" id="ff1_text1" type="text" size="20"><br>
<input name="ff1_text2" id="ff1_text2" type="text" size="20"><br>
<input name="ff1_text3" id="ff1_text3" type="text" size="20"><br>
<div class="input_cell clickable" onClick="toggleTexts()">[%CheckSelect(ff1_dk, 1)%]Don't Know</div>

<script type="text/javascript">
<!--
function toggleTexts()
{
    document.getElementById("ff1_text1").disabled = !document.getElementById("ff1_text1").disabled;
    document.getElementById("ff1_text2").disabled = !document.getElementById("ff1_text2").disabled;
    document.getElementById("ff1_text3").disabled = !document.getElementById("ff1_text3").disabled;
    if (document.getElementById("ff1_text1").disabled) 
    {
        document.getElementById("ff1_text1").value = "Don't Know";
    }
    else
    {
        document.getElementById("ff1_text1").value = "";
    }
}
//-->
</script>

answered Dec 12, 2011 by Bahadir Ozkurt Gold (16,830 points)
That is perfect! Thank you!
...