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);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div><input id="pos1" class="validate" name="Position" required="required" type="checkbox" value="abc">abc</div>
<div><input id="pos2" class="validate" name="Position" required="required" type="checkbox" value="xyz" checked="true">xyz</div>
<div><input id="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
function myFunction(e) {
Logger.log(e.Position) // ["abc", "xyz"] if you ckecked "abc" and "xyz"
}
HTML
<form>
<div><input id="pos1" class="validate" name="Position" required="required" type="checkbox" value="abc">abc</div>
<div><input id="pos2" class="validate" name="Position" required="required" type="checkbox" value="xyz">xyz</div>
<div><input id="pos3" class="validate" name="Position" required="required" type="checkbox" value="pqr">pqr</div>
<input type="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"