Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
How can I make user input case insensitive in an HTML Form in Apps Script?

I have made a custom function on Google Sheets that allows the user to see how much they have spent on an expense.

Here is the example output: Example output

The HTML sidebar:

HTML Sidebar

Here is the JavaScript function:

function perCentBrand(brand){
  var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var values = sh.getRange(2,1,sh.getLastRow()-1,sh.getLastColumn()).getValues();
  var total = 0;
  var sum = 0;
  values.forEach(function(row){
    total+=row[1];
    if (row[6]==brand){sum+=row[1]}
  })
  var val = "You spent a total of " + sum + " on " + brand + " out of " + total + " ." + " Additionally, " + (sum/total)*100 + "%"  + " of your income has been spent on " + brand; 
  var ui = SpreadsheetApp.getUi();
  ui.alert(val)
}

And here is the HTML form code:

    <form onsubmit="runFunc()">
      <input class = "u-full-width " id="brand" type = "text" placeholder="Enter brand name">

    <div class="u-full-width" style="display:flex; justify-content: center">
      <button type="submit" class="button-primary">Submit</button>
    </div>
    </form>

I have read about the toLowerCase() and the toUpperCase() methods but I am unsure if these should be included to make the user input case insensitive.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

function perCentBrand(brand){
  var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var values = sh.getRange(2,1,sh.getLastRow()-1,sh.getLastColumn()).getValues();
  var total = 0;
  var sum = 0;
  values.forEach(function(row){
    total+=row[1];
    if (row[6].toLowerCase() == brand.toLowerCase()){sum+=row[1]}
  })
  var val = "You spent a total of " + sum + " on " + brand + " out of " + total + " ." + " Additionally, " + (sum/total)*100 + "%"  + " of your income has been spent on " + brand; 
  var ui = SpreadsheetApp.getUi();
  ui.alert(val)
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

I'm assuming you mean "make user input case insensitive" regarding your if-statement, so I would control for case there if (row[6].toLowerCase()==brand.toLowerCase()){sum+=row[1]}.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda