I am trying to create variable if a checkbox is checked in a HTML form. But could not succeed to write it back.
Here is my complete HTML code "Index.html":-
<!DOCTYPE html> <html> <head> <base target="_top"> </head> <br> <h1>Add Row To Spreadsheet</h1><br /> <form id='myForm'> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td></td> <td><input type="checkbox" name="name1" id="name1"/>A</td> <td><input type="checkbox" name="name2" id="name2"/>B</td> <td><input type="checkbox" name="name3" id="name3"/>C</td> <td><input type="checkbox" name="name4" id="name4"/>D</td> </tr> <input type="button" value="Submit" onclick="google.script.run .withSuccessHandler(google.script.host.close) .itemAdd(this.parentNode)" /> </table> <br> </form> </html> Mentioned below is my "Code.gs:-
function openInputDialog() { var html = HtmlService.createHtmlOutputFromFile('Index').setSandboxMode(HtmlService.SandboxMode.IFRAME); SpreadsheetApp.getUi() .showModalDialog(html, 'Add Item'); } function itemAdd(form) { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName("Sheet1"); var lastRow = sheet.getLastRow(); var match1 = sheet.getRange("B2").getValue(); var dataRange = sheet.getRange(1, 1,lastRow).getValues(); for(var i=0;i<dataRange.length;i++) { if(dataRange[i][0] == match1) { if(document.getElementById("name1").checked) { days="yes"; sheet.getRange(i+1, 2).setValue(days) } } } } Any Help is appreciated, I think html is complete but I am missing something in code.gs Kindly lt me know if you need any further clarification.