globalzen
globalzen

Reputation: 15

How to do autofocus for a google web app script?

I am writing my first Google webapp. I am trying to setup a form with an input but cannot get focus on the first input. Is there some trick to doing autofocus in google webapps? In the following code focus is not given to the input.

<!DOCTYPE html> <html lang="en"> <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
     </head> <body>
    <form>
      <h1>Enter Loan Details</h1>
      <br>
      <label for="multiInput">Scan Number / Name or Hardware Tag</label>
      <input type="text" id="multiInput" name="multiInput"  autofocus>
    </form>   </body> </html>

Upvotes: 0

Views: 348

Answers (1)

Cooper
Cooper

Reputation: 64100

Focus on element of your choice

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
     <h1>Hello</h1>
     <label>Your name: </label>
     <input id="first" type="text" size = "25" />
     <script>
       //waits for window to load
       window.onload = function() {
         document.getElementById('first').focus();
       }
     </script> 
  </body>
</html>

    function showdialog() {
      let ui = SpreadsheetApp.getUi();
      ui.showModelessDialog(HtmlService.createHtmlOutputFromFile('ah2'),Test Dialog')
    }

Upvotes: 1

Related Questions