I wrote a script for my Google Spreadsheet and but it doesn't work as expected. I have a Sheet with customer data. The first column (column A) shouldn't get an entry because that's the customer ID and it will be automatically set when I put a name in column B. So I want the script to start the entry from the second column (column B) on.
How do I tell my script to start the entry from the second column (column B)? It currently starts the entry from column A.
My script
function onOpen(){
var ui=SpreadsheetApp.getUi();
ui.createMenu("Eintrag")
.addItem("Sidebar form", "showInsidebarform")
.addToUi();
}
//OPEN THE FORM IN SIDEBAR
function showInsidebarform() {
var userform=HtmlService.createTemplateFromFile("form").evaluate().setTitle("Daten eintragen");
SpreadsheetApp.getUi().showSidebar(userform);
}
function appenData(data){
var ws=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Schüler")
ws.appendRow([data.name,data.vname]);
}
The html code
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
</div class="container">
<div class="row">
<div class="input-field col s12">
<i class="material-icons prefix">account_circle</i>
<input id="name" type="text" class="validate">
<label for="name">Nachname</label>
</div>
<div class="input-field col s12">
<i class="material-icons prefix">account_circle</i>
<input id="vname" type="text" class="validate">
<label for="vname">Vorname</label>
</div>
<div class="input-field col s12">
<button class="btn waves-effect waves-light" id="btn">Submit
<i class="material-icons right">send</i>
</button>
</div>
</div><!--end row-->
</div>
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script>
var nameBox=document.getElementById("name");
var vnameBox=document.getElementById("vname");
document.getElementById("btn").addEventListener("click",addRecord);
function addRecord(){
var name=nameBox.value;
var vname=nameBox.value;
if(name.trim().length==0||vname.trim().length==0){
M.toast({html: 'haha'})
}
var data={
name:nameBox.value,
vname:nameBox.value
};
google.script.run.appenData(data);
nameBox.value="";
vnameBox.value="";
}
</script>
</body>
</html>