'appscript form.data[x] increment
=== Answer added in code ===
please could you help me resolve this :
How get form.test[j] work in the Apps Script code of the form submit.
Input name are : test1 test2 test3 ....
information :
with <?= r[0] ?> = num 1 to 40
2.html code of modal (working) :
<!DOCTYPE html>
<html>
<head>
<script src="https://apis.google.com/js/api.js?onload=onApiLoad">
</script>
<script>
function submitForm() {
google.script.run.appendRowFromFormSubmit(document.getElementById("formulaire"));
document.getElementById("form").style.display = "none";
document.getElementById("thanks").style.display = "block";
}
</script>
<style>
body {
padding: 0 0.5rem; /* à remplacer par "margin: 0;" si affiché dans une boîte de dialogue */
color: #333;
font-family: Roboto, Arial, sans-serif;
overflow: scroll;
}
p {
margin: 0.8rem 0 0.3rem;
}
.annuler {
display: inline-block;
margin-top: 1rem;
font-size: 0.88rem;
color: #888;
cursor: pointer;
}
.annuler:hover {
text-decoration: underline;
}
input[type="text"] {
display: block;
width: 100%;
box-sizing: border-box;
margin-bottom: 1rem;
padding: 0.6rem 0.7rem;
background: #f3f3f3;
color: #444;
border: none;
font-size: 1.08rem;
border-radius: 0.4rem;
}
input[type="button"] {
display: block;
width: 100%;
padding: 0.7rem 0 0.6rem;
border: none;
background: #30a392;
color: #fff;
font-size: 1.15rem;
cursor: pointer;
border-radius: 0.4rem;
}
input[type="button"]:hover {
background: #40ad96;
}
input[type="radio"]:hover {
cursor: pointer;
}
#finbouton
{
overflow: hidden;
height: 50px;//800px;
}
p{
background-color: #D3D3D3;
}
</style>
</head>
<body>
<div id="form"><form id="formulaire">
<input type="button" id="form" name="form" value="Enregistrer" onclick="submitForm();">
</div>
<table>
<? htmlOrders().forEach(r => {?>
<tr>
<td><input type="checkbox" id="test<?= r[0] ?>" name="test<?= r[0] ?>" value="checked" <?= r[1] ?> ></td>
<td><?= r[2] ?></td>
</tr>
<?})?>
</table>
</form>
</div>
<div id="thanks" style="display: none;"><br><b>Attendre la fin de l'enregistrement.</b>
</div>
</body>
</html>
here app script code (form.test[j] not working)
function appendRowFromFormSubmit(form) {
var spreadsheet = SpreadsheetApp.getActive();
var sheet2 = spreadsheet.getSheetByName('Valeurs');
var email = Session.getActiveUser().getEmail();
var nbrows = sheet2.getRange("F1").getValue();
for(var j = 1; j <= nbrows; j = j+1){
if (form["test" + j] != "1"){ // === Answer here ===
var rowdata = "";
}
else{
var rowdata = "checked";
}
var data1 = sheet2.getRange("H" + j).getValue();
if (data1 != rowdata) {
sheet2.getRange("I"+ j).setValue(email);
sheet2.getRange("H"+ j).setValue(rowdata);
}
};
}
Thanks for your help
As requested, here the secondary app script code
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('=> Menu ZCS <=')
.addItem('Suivi', 'suivi')
.addToUi();
}
function suivi() {
var ui = HtmlService.createTemplateFromFile('2')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Suivi ZCS') ;
SpreadsheetApp.getUi().showSidebar(ui);
}
function htmlOrders() {
var active = SpreadsheetApp.getActive();
var sheet = active.getSheetByName("Valeurs");
var myRange = sheet.getRange("G1:K40");
return data = myRange.getValues();
}
Objective is to valid step by step a tutorial. And update checkbox statut on H:H
Table : sheet name : "Valeurs"
F | G | H | I | J | K |
---|---|---|---|---|---|
=COUNTIF(G:G;"<>") | 1 | checked | r1 | t1 | |
2 | r2 | t2 | |||
3 | checked | r3 | t3 | ||
4 | r4 | t4 | |||
5 | r5 | t5 | |||
6 | r6 | t6 |
Solution 1:[1]
Use form['test${j}']
or form["test" + j]
The form is an object
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Zogzog |