Home > Back-end >  How to do autofocus for a google web app script?
How to do autofocus for a google web app script?

Time:11-09

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>

CodePudding user response:

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')
    }
  • Related