Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:18:18+00:00 2026-06-07T09:18:18+00:00

How do you add or subtract from a number when you click on a

  • 0

How do you add or subtract from a number when you click on a button. I want to simply say

if (button.click){
    num++;
}

How can I do something like that with the google apps script buttons? Things seem a bit less straightforward to me as I’ve never used a click handler. Its probably some simple thing that I’m missing. Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:18:20+00:00Added an answer on June 7, 2026 at 9:18 am

    please have a look at this demo code :

    var sh = SpreadsheetApp.getActiveSheet();
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    //
    function move() {
       var app = UiApp.createApplication().setTitle("move test")
           .setHeight(100).setWidth(400).setStyleAttribute("background-color","beige");
       var panel = app.createVerticalPanel();
       var next = app.createButton('next').setWidth('180');
       var chkmode = app.createCheckBox("moving mode (checked = up/dwn, unchecked=L/R)").setValue(false).setName('chkmode');
       panel.add(next).add(chkmode);
       var handler = app.createServerHandler('click').addCallbackElement(panel);
       next.addClickHandler(handler);
       app.add(panel);
       ss.show(app);
     }
    //
    function click(e) {
      var app = UiApp.getActiveApplication();
      var activeline = sh.getActiveRange().getRow();// get the row number of the selected cell/range
      var activecol = sh.getActiveRange().getColumn();// get the row number of the selected cell/range
      var chkmode=e.parameter.chkmode;// this returns a string, that's why true is written "true" just below...
      if(chkmode=="true"){
        ++activeline
        }else{
          ++activecol} // the ++ can be before or after the var name, your choice ;-)
      var sel=sh.getRange(activeline,activecol);
      sh.setActiveSelection(sel);// make the next row or column active
      return app;
     }
    

    EDIT : (following your secondary question) to get a Label showing the cell’s content you can use this code in the handler function :

    function click(e) {
      var app = UiApp.getActiveApplication();
      var activeline = sh.getActiveRange().getRow();// get the row number of the selected cell/range
      var activecol = sh.getActiveRange().getColumn();// get the row number of the selected cell/range
      var cellvaluestring = sh.getActiveRange().getValue().toString();
      var label = app.getElementById('label');
      label.setText(cellvaluestring);
      var chkmode=e.parameter.chkmode;
      if(chkmode=="true"){
        activeline++
        }else{
          activecol++}
      var sel=sh.getRange(activeline,activecol);
      sh.setActiveSelection(sel);// make the next row active
      return app;
     }
    

    and in the Ui definition you have to create the label like this :

       var label = app.createLabel("test Label with text that will be modified on click").setId('label');
       panel.add(label);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to call a method that will add or subtract 1 from a
You can add and subtract 1 from my cell.textLabel.text . I am adding 1
I would like an alogrithm that would use only shift, add or subtract operations
For my website, I want to make something that works a bit like the
I wrote a program to multiply, divide, add, and subtract fractions..I just can't figure
I have a group of files (of varying line number) that always finish like
This is embarrassing, but: Let say I want to add 1 to x until
This seems like something that should be easy, but I am having a tough
I need to subtract an X number of minutes from the current date and
I want to let users easily add and subtract dates using JavaScript in order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.