0

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.

1 Answer 1

1
  1. Remove the value from checkbox, otherwise it will be always true.

  2. 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>

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much. So I assume once that var is passed to the js it will be either true or false? You've helped a lot! Grateful.
Yes, second argument in the create function will be true/false.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.