Can't pass multiple parameters in an onclick function

大憨熊 提交于 2019-12-11 05:45:00

问题


I am trying to create an upload mechanism wherein I can upload a file in google drive by using it's file ID from HTML. I don't want to place the ID of the folder inside the upload function as this is needed. I am trying to pass multiple arguments on function upload(e) by declaring another parameter i.e. function upload(e,id). I am aware that the function is trigged in the HTML by this onclick="google.script.run.withSuccessHandler(updateUrl).upload(this.parentNode)"

I tried to add another parameter by onclick="google.script.run.withSuccessHandler(updateUrl).upload(this.parentNode, '1234thisisanexampleid')"

Where 1234thisisanexampleid is a string. I am also not sure how the this.parentNode as well. I have also seen results of adding commas in parameters but I also don't understand how it works.

 //code gs    
 function doGet() {
  return HtmlService.createHtmlOutputFromFile('Form.html');
}

function upload(e) { 



 // Folder ID of destination folder
 var destination_id = xxx;



var img = e.imageFile;

var destination = DriveApp.getFolderById(destination_id);

destination.createFile(img);

return "File Uploaded Successfully!";
}



//Form.html (just a part of the code)
<form>
  <input type="file" name="imageFile">
  <input type="button" value="Upload File" onclick="google.script.run.withSuccessHandler().upload(this.parentNode)">
</form>

回答1:


Issue:

A form element within the page is also legal as a parameter, but it must be the function’s only parameter, and it is not legal as a return value.

As written in the official documentation, It is not possible to send two parameters, while one of them is a form.

Solution:

Send it inside the form as input.

<input type="hidden" name ="folderId" value="1234thisisanexampleid">


来源:https://stackoverflow.com/questions/54214979/cant-pass-multiple-parameters-in-an-onclick-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!