Have an idea?

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

Javascript working in preview, but not in browser


I have the following script in the footer of a select question - it is to grey out the checkbox labels when the "None of these" option is selected (per to my previous question, as I had no answers, I'm trying this myself!):

<script type="text/javascript">
var TS = new Array;
TS[0]= document.getElementsByTagName("label")[0];
TS[1]= document.getElementsByTagName("label")[1];
TS[2]= document.getElementsByTagName("label")[2];
TS[3]= document.getElementsByTagName("label")[3];
TS[4]= document.getElementsByTagName("label")[4];
TS[5]= document.getElementsByTagName("label")[5];
TS[6]= document.getElementsByTagName("label")[6];

window.onload = function() {
document.getElementById("A3_8").onclick = changeColor;
function changeColor(){
if (document.getElementById("A3_8").checked)  {

for (var i=0; i<=(6); i++){ TS[i].style.backgroundColor="#CFCFCF"; }
 } else if (document.getElementById("A3_8").unchecked)  {
  for (var i=0; i<=(6); i++){ TS[i].style.backgroundColor=""; }    

As the heading suggests, this is working when I preview the page, but not when uploaded into a browser. What am I missing? Please help!
asked Jan 23, 2012 by anonymous

1 Answer

0 votes
Hi cass74,

your code does work in test mode as well, only change I've made is replacing
else if (document.getElementById("A3_8").unchecked)

else if (!document.getElementById("A3_8").checked)

but I've made this change because your original code didn't change backgrounds back to none even in preview mode.
answered Jan 23, 2012 by Bahadir Ozkurt Gold (16,980 points)