2

I want to use the "check box" operation of google sheets, and when the check box is true, then call to a function. Someone can help me with that ?

3
  • What do you mean by Check Box? As in an input field checkbox? Commented Nov 22, 2018 at 20:44
  • A new feature that enable to create a clickable check box that return true or false on a click. I want to associate the check box to a function. Commented Nov 22, 2018 at 20:48
  • Are you trying to do this with HTML and Javascript? The google-sheets part is confusing me, does it need to relate to google-sheets or do you want an example of check boxes? Commented Nov 22, 2018 at 20:50

2 Answers 2

2

Supposing your checkbox is at A1, you could use this script to test when it's checked or unchecked (modified):

function onEdit(e) {
  var range = e.range;
  if (range.getA1Notation() == 'A1') {
    var value = range.getValue();
    range.setNote('Changed on ' + new Date() + ' to ' + range.getValue());
    if (typeof value === 'boolean' && value == true) {
      // Do something or call a function when the tick box is checked
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

While I'm unsure of exactly what you want to do in javascript, the Google Script editor may be useful for you.

In a Google Sheet, go to Tools > Script Editor. It should open a new page and create a new project with a blank function. This is where you can make new functions to be run within Google Sheets.

As an example I made a function called getSum:

function getSum(a,b) {
return a+b;
}

If you save this script and go back to Sheets, you can do =getSum(1,2) and it will return 3

If you wanted to integrate this with a Tick Box, you could do =IF(A1,getSum(1,2),getSum(2,2))

In this case, when the tick box is checked, it will run the first statement, and return 3 , when the box is unchecked, it will return 4

I'm not entirely sure on what you are trying to achieve with JavaScript, but this is one way to introduce custom functions (using Google Script).

1 Comment

Thank you for the details, appreciate it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.