Skip to content Skip to sidebar Skip to footer

How To Get Values Of All Checked Checkboxes In Google App Script

I am using App script which takes HTML form input & writes it into Google Sheet. I am running it on form submit as below: google.script.run .appscriptfunc(); While

Solution 1:

You could use .each() to iterate over the checked checkboxes and collect the values in an array by pushing it into it.

var values = [];
$("input[type='checkbox'][name='Position']:checked").each(function(i, e) {
  values.push(e.value);
});
console.log(values);
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><inputid="pos1"class="validate"name="Position"required="required"type="checkbox"value="abc">abc</div><div><inputid="pos2"class="validate"name="Position"required="required"type="checkbox"value="xyz"checked="true">xyz</div><div><inputid="pos3"class="validate"name="Position"required="required"type="checkbox"value="pqr">pqr</div>

Solution 2:

How about this? If you checked "abc" and "xyz" and push the submit button, {Position: ["abc", "xyz"] is returned.

GAS

functionmyFunction(e) {
  Logger.log(e.Position) // ["abc", "xyz"] if you ckecked "abc"and"xyz"
}

HTML

<form><div><inputid="pos1"class="validate"name="Position"required="required"type="checkbox"value="abc">abc</div><div><inputid="pos2"class="validate"name="Position"required="required"type="checkbox"value="xyz">xyz</div><div><inputid="pos3"class="validate"name="Position"required="required"type="checkbox"value="pqr">pqr</div><inputtype="submit"value="Submit"onclick="google.script.run.myFunction(this.parentNode);" /></form>

If this was not what you want, I'm sorry.

Post a Comment for "How To Get Values Of All Checked Checkboxes In Google App Script"