0

I created a web app through google app script, which could generate a table of data for users to select for calculation. So I would generate a table with values and checkboxes through google sheet.(the table size may differ between users). There is my sample code.

<form role="qryForm" method="post" action="<?!= ScriptApp.getService().getUrl() ?>">
 <button class="btn btn-success" type="submit" value="Submit">
 <table>
   <tr>
        <td><input type="checkbox" onchange="changeName(this)" name="uncheck" value ="100"></td>
        <td>100</td>
   </tr>

   <tr>
        <td><input type="checkbox" onchange="changeName(this)" name="uncheck" value ="200"></td>
        <td>200</td>
   </tr>

 </table>
</form>

When the checkbox is clicked, a small function will change the name of input to be "checked".

However, when the submit button is pressed, only the checked parameter is returned to the server. I looked at the event object (e.parameters), it dose not return the values under the name of "uncheck"

I am expecting to get something like: check:[1,2,3,4], uncheck:[5,6,7,8]

How do I get it down? or how do I get the values of all checkboxes in google appscript?

Joey F. Ku
  • 13
  • 1
  • 3
  • Hello! May I ask, why are you even changing the "name" of your checkboxes? Please bear in mind that the [name attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname) should never be repeated within a form (each element should have its distinct `name`) – carlesgg97 Nov 26 '19 at 12:22
  • Thanks for the reminder. It is a mistake. – Joey F. Ku Nov 26 '19 at 15:53
  • No worries. After correcting this, do you still have issues? If so, kindly update your original question with any issue you may have (if it is relevant to the original question) – carlesgg97 Nov 26 '19 at 15:58
  • Unfortunately, It did not solve my problem. I use auto generated input name attribute, so that every name attribute is different. The form still only returned values that has been checked. Like this : – Joey F. Ku Nov 27 '19 at 05:19
  • {parameter={flag=true, check=2}, contextPath=, contentLength=29, queryString=, parameters={flag=[true], check=[2, 3]}, postData=FileUpload} . the "flag" is another Input named flag outside the form, and the "check" are those checkboxes that have been clicked – Joey F. Ku Nov 27 '19 at 05:20

1 Answers1

0

From the W3C HTML 4 guidelines:

Checkboxes (and radio buttons) are on/off switches that may be toggled by the user. A switch is "on" when the control element's checked attribute is set. When a form is submitted, only "on" checkbox controls can become successful.

Essentially - unchecked checkboxes are not sent along with the form, only the checked ones.

There are many workarounds which you may learn about here: POST unchecked HTML checkboxes

carlesgg97
  • 4,184
  • 1
  • 8
  • 24