0

I have a form in a html file inside my google apps script project, I need to redirect to another html file when a submit button is Clicked.

HTML CODE:

 <html>
      <script>
        function doSomething(){
          alert('this one works too!'); 
          //here Change of page
        }
      </script>

     <body>
        <h1 style="text-align:center;font-family:Tahoma;">HORAS LABORADAS<br/>    
        <form style="margin-left:90px;font-family:Trebuchet MS;">
          <b>Nombre</b><br/>
          <input type="button" onclick="doSomething()">
        </form>
      </body>
 </html>

I call this by

function doGet() {
  return HtmlService.createTemplateFromFile('prueba').evaluate();
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
LawCorredor
  • 23
  • 1
  • 1
  • 6

2 Answers2

2

HTML FILE1

      <html>
          <body>
            <h1 style="text-align:center;font-family:Tahoma;">HORAS LABORADAS<br/>    
            <form style="margin-left:90px;font-family:Trebuchet MS;">
              <b>Nombre</b><br/>
              <?var url = getUrl();?><a href='<?=url?>?page=2'><input type='button' name='test' value='GO TO PAGE 2'></a>
            </form>
          </body>
     </html>

HTML FILE2

<html>
  <h1>This is Page 2.</h1><br/>
 <?var url = getUrl();?><a href='<?=url?>?page=1'>  <input type='button' name='test' value='RETURN TO PAGE 1'></a>
</html>

CODE.GS

function getUrl(){
  var url = ScriptApp.getService().getUrl();
  return url;
}

 function doGet(requestInfo) {
      var url = ScriptApp.getService().getUrl();
      if (requestInfo.parameter && requestInfo.parameter['page'] == '2') {
        return HtmlService.createTemplateFromFile('FILE2').evaluate();
      }
      return HtmlService.createTemplateFromFile('FILE1').evaluate();
    }
LawCorredor
  • 23
  • 1
  • 1
  • 6
-1

If you simply want to redirect to another page, use the following:

<script>
    function doSomething(){
      alert('this one works too!'); 
      window.location.href = "http://myurl.com";
    }
</script>

Source: click this link

Community
  • 1
  • 1
ThunderCat
  • 68
  • 6