Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
The button effect only works after the function ends

On my sidebar, there are two buttons button1 and button2. What I want is, after button1 is clicked then myfunction() will run simultaneously button2 is disabled. When myfunction() ends, button2 switches to enable state. I used the following code:

$(document).ready(function(){
    $("#button1").click(function(){
        google.script.run.myfunction();
            $("#button1").attr("disabled",true);
            $('#button2').attr("disabled", false);
        });
    });
});

However, when button1 is clicked, the function myfunction() runs and button2 is also enabled. This causes the user to click button2 while the function is running, resulting in an error. Can anyone help me? Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This looks like a job for Promises. Use async-await to achieve this.

google.script.run.myfunction should be an async call.

Disable your button before the function is run. Then in the second line, we wait for the result from myfunction execution. Later, we toggle the disabled attribute.

$(document).ready(function(){
    $("#button1").click(async function(){
            $("#button1").attr("disabled",true);        
let newVal = await google.script.run.myfunction();
            $('#button2').attr("disabled", false);
        });
    });
});

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!