简体   繁体   English

HTML复选框为Javascript形式

[英]HTML checkbox to Javascript form

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: 相关的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. @umair在我的html中指出了方向,如下所示。 My js, however, used pledge instead of pledgeCheck in the arguments. 但是,我的js在参数中使用了pledge而不是pledgeCheck。

  1. Remove the value from checkbox, otherwise it will be always true. 从复选框中删除该值,否则它将始终为true。

  2. Check whether the checkbox is checked or not with .checked attribute and not with .value ; 检查是否使用.checked属性而不是.value复选框。 this will return true for checked and false for unchecked. 如果选中,则返回true;如果未选中,则返回false。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM