Skip to content

Instantly share code, notes, and snippets.

@Dms-Codee
Last active January 28, 2024 20:19
Show Gist options
  • Select an option

  • Save Dms-Codee/13d88e2b4c9dae7e914da1139a1175f9 to your computer and use it in GitHub Desktop.

Select an option

Save Dms-Codee/13d88e2b4c9dae7e914da1139a1175f9 to your computer and use it in GitHub Desktop.
Selec_List_Example_GoogleAppScript
function doGet(){
var template =HtmlService.createTemplateFromFile('index');
var html = template.evaluate();
return html;
}
function getList(){
var ss=SpreadsheetApp.getActiveSpreadsheet();
var listaBDRoja= ss.getSheetByName("TablaRoja").getDataRange().getValues();
var listaBDAzul= ss.getSheetByName("TablaAzul").getDataRange().getValues();
var listaBDAmarilla= ss.getSheetByName("TablaAmarilla").getDataRange().getValues();
var objectDB = {
listaRoja: listaBDRoja,
listaAzul: listaBDAzul,
listaAmarilla:listaBDAmarilla
}
return objectDB;
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<select name="select" id="tableColor" onchange="renderizar()">
<option value="Rojo">Lista Rojo</option>
<option value="Azul">Lista Azul</option>
<option value="Amarilla">Lista Amarilla</option>
</select>
<select name="select" id="colorList">
</select>
<script>
var frontListaRoja;
var frontListaAzul;
var frontListaAmarilla;
window.addEventListener ('load', ()=> {
google.script.run
.withSuccessHandler(cargarData)
.withFailureHandler(muestraError)
.getList();
})
function cargarData(objectDB){
frontListaRoja = objectDB.listaRoja;
frontListaAzul = objectDB.listaAzul;
frontListaAmarilla= objectDB.listaAmarilla;
var $colorList = document.getElementById('colorList');
var ourFragment = '';
for (i=1; i<frontListaRoja.length; i++){
ourFragment +=
`
<option value="${frontListaRoja[i][0]}"> ${frontListaRoja[i][0]}</option>
`
}
$colorList.innerHTML += ourFragment;
}
function muestraError(error){
console.log(error);
}
function renderizar(){
var $tableColor= document.getElementById('tableColor').value
var $colorList = document.getElementById('colorList');
var ourFragment = '';
switch($tableColor){
case 'Rojo':
$colorList.innerHTML ='';
for (i=1; i<frontListaRoja.length; i++){
ourFragment +=
`
<option value="${frontListaRoja[i][0]}"> ${frontListaRoja[i][0]}</option>
`
}
$colorList.innerHTML += ourFragment;
break;
case 'Azul':
$colorList.innerHTML ='';
for (i=1; i<frontListaAzul.length; i++){
ourFragment +=
`
<option value="${frontListaAzul[i][0]}"> ${frontListaAzul[i][0]}</option>
`
}
$colorList.innerHTML += ourFragment;
break;
case 'Amarilla':
$colorList.innerHTML ='';
for (i=1; i<frontListaAmarilla.length; i++){
ourFragment +=
`
<option value="${frontListaAmarilla[i][0]}"> ${frontListaAmarilla[i][0]}</option>
`
}
$colorList.innerHTML += ourFragment;
break;
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment