Can't pass multiple parameters in an onclick function

问题: 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...

问题:

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">
  • 发表于 2019-01-18 22:21
  • 阅读 ( 195 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除