0

I am trying to design a survey through google sheets and have set up some checkboxes, but noticed that there is some lag when changing selections/clearing previous selection. I was wondering if there is any way to modify the script or another way to set this up to minimize any lag.

Below is what I'm currently using:

function onEdit1(e) {
  var CHECKBOX_CELLS = ["A37", "A38", "A39", "A40", "A41", "A42","A43","A44"];   
  var range = e.range;

  var checkboxIndex = CHECKBOX_CELLS.indexOf(range.getA1Notation());

  if (checkboxIndex > -1 && range.getValue() == true) {
    var sheet = range.getSheet();

    for (var i=0; i<CHECKBOX_CELLS.length; i++) {
      if (i==checkboxIndex) continue;

      sheet.getRange(CHECKBOX_CELLS[i]).setValue(false);
    }
  } 
}

I also tried the following, but I have 2 questions I need radio buttons for and using the below would only allow one selection across question 1 and 2. Question one has check boxes in cells A37-44 and Question two has them in A49-55

function onEdit(e){
    
  if(e.source.getActiveSheet().getName() != "Sheet Name" || e.range.columnStart != 1 || e.value == "FALSE") return;   
    for(var i = 37;i<45;i++){
      if(i == e.range.rowStart) continue;
        e.source.getActiveSheet().getRange(i,2).setValue("FALSE");
      } 
    }
}

Any guidance is much appreciated as I'm not familiar setting this up in google.

Thank you!

  • 1
    Welcome. Two questions: 1) why use Google sheets for the survey - why not use Google Forms and pull the results into Google sheets. 2) this onEdit snippet makes little/no sense since all it does it sets any existing "true" values to false - what's the point of that? Yes, there is a slight lag, maybe partly due to using getRange() and setValue() inside a loop; but why loop at all? Would you please edit your question to explain what you are trying to achieve with your code. – Tedinoz Aug 11 at 6:13
  • Tess, did you resolve your question, or are you still looking for assistance? – Tedinoz Aug 23 at 3:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.