Reputation: 63
I am (still) working on creating sidebar input for a Sheets add-on I'm developing. My current challenge is allowing a textbox and a checkbox to be passed from the form to my function.
The textbox works and successfully passes the variable. The checkbox I'm not as clear on. I need to turn the checkbox into a boolean.
The relevant html:
<p>
<input type="text" id="datepicker">
</p>
<p>
Include pledge?<br>
<input type="checkbox" name="pledge[]" id="pledgeCheck" value="true">Yes<br>
</p>
<p>
<input type="button" name="createdate" value="Create" onClick="google.script.run.create(document.getElementById('datepicker').value,document.getElementById('pledgeCheck').value)" />
</p>
function create(datepicker,pledge) {
//important vars
var responses = ss.getSheetByName("Form Responses");
var bulletin = ss.getSheetByName(todayDate);
var todayDate=datepicker;
var pledgeCheck=pledge;
Logger.log(pledgeCheck);
currently the pledge feeds back as undefined.
SOLVED: A few things I wasn't getting, and maybe a few I just sort of overlooked and missed. I didn't have the right terms in all the right places. @umair pointed the way in my html, as shown below. My js, however, used pledge instead of pledgeCheck in the arguments.
Upvotes: 0
Views: 87
Reputation: 4635
Remove the value from checkbox, otherwise it will be always true.
Check whether the checkbox is checked or not with .checked
attribute and not with .value
; this will return true for checked and false for unchecked.
<p>
<input type="text" id="datepicker">
</p>
<p>
Include pledge?<br>
<input type="checkbox" name="pledge" id="pledgeCheck">Yes<br>
</p>
<p>
<input type="button" name="createdate" value="Create" onClick="google.script.run.create(document.getElementById('datepicker').value,document.getElementById('pledgeCheck').checked)" />
</p>
Upvotes: 1