Good Morning,
I created a html form to change values from a google spreadsheet. I was able to do the trick, but I want the form to be pre-filed with some values from the spreadsheet. I have no idea on how to do that. I don't have much experience in programming, so I would be very grateful if someone could help me.
Here is the code I'm using
GS file:
function editDadosPessoais() {
var ss = SpreadsheetApp.getActiveSpreadsheet(),
html = HtmlService.createHtmlOutputFromFile('DadosPessoais')
ss.show(html);
}
HTML file:
<html>
<head>
<meta content="Sheets" name="generator" />
<style type="text/css"><!--br {mso-data-placement:same-cell;}
.auto-style3 {
font-family: Calibri;
}
.auto-style4 {
font-family: Calibri;
text-decoration: underline;
}
.auto-style5 {
text-decoration: underline;
}
--></style>
<meta content="pt-br" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<form name="DadosPessoais" action="" method="post" style="width: 473px; height: 454px" onsubmit="formSubmit(this)">
<strong><span class="auto-style4">NOME:</span></strong><span class="auto-style3"><strong>
</strong></span><strong>
<input class="auto-style3" name="Name1" id="Name1" style="width: 382px" type="text"/><br />
<br class="auto-style3" />
<span class="auto-style3"><span class="auto-style5">CÓDIGO DEPENDENTE:</span>
</span><select class="auto-style3" name="Dep1" id="Dep1" style="width: 76px">
<option>Titular</option>
<option>Esposo(a)</option>
<option>Filho(a)</option>
<option>Outro(a)</option>
</select><br />
<br class="auto-style3" />
<span class="auto-style3"><span class="auto-style5">TELEFONES:</span>
<span class="auto-style5">SITUAÇÃO: </span></span>
<br class="auto-style3" />
<input class="auto-style3" name="Tel1" id="Tel1" type="text"/><span class="auto-style3">
</span><select class="auto-style3" name="SitTel1" id="SitTel1" style="width: 97px">
<option></option>
<option>CORRETO</option>
<option>ERRADO</option>
</select><br class="auto-style3" />
<input class="auto-style3" name="Tel2" id="Tel2" type="text"/><span class="auto-style3">
</span><select class="auto-style3" name="SitTel2" id="SitTel2" style="width: 97px">
<option></option>
<option>CORRETO</option>
<option>ERRADO</option>
</select><br class="auto-style3" />
<input class="auto-style3" name="Tel3" id="Tel3" type="text" /><span class="auto-style3">
</span><select class="auto-style3" name="SitTel3" id="SitTel3" style="width: 97px">
<option></option>
<option>CORRETO</option>
<option>ERRADO</option>
</select><br />
<br class="auto-style3" />
<span class="auto-style3"><span class="auto-style5">EMAIL:</span> </span>
<input class="auto-style3" name="Email1" id="Email1" style="width: 329px" type="text" /><br />
<br class="auto-style3" />
<span class="auto-style4">ENDEREÇO:<br />
</span><br class="auto-style4" />
<span class="auto-style3">Logradouro: </span>
<input class="auto-style3" name="Log1" id="Log1" style="width: 271px" type="text" /><span class="auto-style3">
nº: </span>
<input class="auto-style3" name="Number1" id="Number1" style="width: 59px" type="text" /><span class="auto-style3"><br />
<br />
Complemento: </span>
<input class="auto-style3" name="Comp1" id="Comp1" style="width: 91px" type="text" />
<span class="auto-style3">Bairro: </span>
<input class="auto-style3" name="Bairro1" id="Bairro1" style="width: 197px" type="text" /><span class="auto-style3">
<br /> <br />
Cidade: </span>
<input class="auto-style3" name="Cid1" id="Cid1" style="width: 276px" type="text" /><span class="auto-style3">
Estado: </span>
<select class="auto-style3" name="Estado1" id="Estado1" style="width: 55px">
<option></option><option>AC</option><option>AL</option><option>AP</option><option>AM</option><option>BA</option><option>CE</option><option>DF</option><option>ES</option><option>GO</option><option>MA</option><option>MG</option><option>MS</option><option>MT</option><option>PA</option><option>PB</option><option>PE</option><option>PI</option><option>PR</option><option>RJ</option><option>RN</option><option>RO</option><option>RR</option><option>RS</option><option>SC</option><option>SE</option><option>SP</option><option>TO</option>
</select><br class="auto-style3" />
<br class="auto-style3" />
<div>
<input type="submit" class="button redButton" value="Submit">
</div>
</form>
<script type="text/javascript">
function formSubmit(argTheFormElement) {
google.script.run
.withFailureHandler(myFailureFunction)
.withSuccessHandler(google.script.host.close)
.getValuesFromForm(argTheFormElement);
}
function myFailureFunction(argError) {
alert("There was an error: " + argError.message);
google.script.host.close();
}
</script>
</body>
</html>