1

I have two buttons Start and Next. I want that, initially the Start button is in the enabled state, and the Next button is in the disabled state. After the user clicks on the Start button, a function will run, and when the function is finished, the Next button will switch to the enabled state. I used the following code:

<button id="start" onclick="myfunction1" >Start</button>
<button id="next" onclick="myfunction2" disabled="disabled">Next</button>
<script>
function myfunction1(){
  google.script.run.openUrl();
  document.getElementById("start").disabled = true;
  document.getElementById("next").disabled = false;
}
</script>

When I click on the Start button, the function myfunction1() runs, and at the same time the Start button changes to the disabled state and the Next button changes to the enabled state. However, after the myfunction() function completes, the Start button returns to the enabled state and the Next button returns to the disabled state. I don't know how to solve it. I really need help. Thanks.

Le tone
  • 23
  • 2
  • 2
    Clicking the button also submits your
    , and since it doesn't have a method or action attribute, that is essentially like reloading the page, which resets your buttons. A quick fix is to add `type="button"` to your
    –  Sep 29 '21 at 15:23
  • Are the buttons inside a `
    `?
    – Barmar Sep 29 '21 at 15:24
  • 1
    I added `type="button"` to my ` – Le tone Sep 29 '21 at 15:50
  • *Exactly* what does `google.script.run.openUrl();` do? Looks like it reloads the page. – freedomn-m Sep 29 '21 at 16:10
  • `google.script.run.openUrl()` creates copies of a form in Google drive into multiple forms and places them in the same folder. – Le tone Sep 29 '21 at 16:16
  • Check your browser's network tab to see what it's doing and when. Remove all code that enables the start button (except the default html enabled). If it's still getting enabled, then it's definitely your page being reloaded and it's not in (just) the code you've provided. – freedomn-m Sep 29 '21 at 16:19
  • Thanks **freedomn**, it's true that `google.script.run.openUrl()` has something to do with some triggering and doing page reloads. What should I do in this case? – Le tone Sep 29 '21 at 18:13

0 Answers0