2012-09-27 77 views
0

我知道issue 1660已被標記爲固定,但我似乎無法獲取從我的htmlservice表單傳遞給我的谷歌應用程序腳本的任何參數。這是我曾嘗試:「google.script.run.function」不從htmlservice傳遞值

<my html file> 
<form id="myForm"> 
    <input name="aField" id="aField"> 
    <input type="button" id="submit" value="submit" onclick = "sendData()"> 
</form> 

<script> 
function sendData() { 
    google.script.run.processForm(document.getElementById("myForm")); 
} 
</script> 
</my html file> 

<google apps script> 
    function processForm(value) { 
     var range = SpreadsheetApp.openById("1234").getRangeByName("testRnage"); 
     range.setValue(value.aField); 
    } 
    </google apps script> 

使用

<input type="button" id="submit" value="submit" onclick = "google.script.run.processForm(this.parentNode)">也不起作用。

這兩種方法都會導致以下瀏覽器錯誤:「Uncaught ScriptError:TypeError:Can not call method」setValue「of null。」

任何幫助表示讚賞。謝謝。

+0

如果您覺得您的問題(現在無用,因爲您發現它是一個簡單的錯字)混亂了StackOverflow,您可以自由刪除它。 – nalply

回答

0

我一直在做這個成功:

var invoice = new Object(); 

invoice.customerCode = selectedCustomer.value; 
invoice.discount = document.getElementById('discount').value; 
invoice.items = blah, blah, blah . . . 

var jsonInvoice = JSON.stringify(invoice); 

google.script.run.recordInvoice(jsonInvoice); 

......與此服務器上...

function recordInvoice(jsonInvoice) { 
    var theInvoice = eval("(" + jsonInvoice + ")"); 
    var cust = theInvoice.customerCode; 

隨意問了闡述,如果這似乎不完整的。

+0

我討厭這樣說,但由於我的代碼中存在拼寫錯誤,所以無法正常工作。我試圖將定義的範圍作爲「testRnage」而不是「testRange」來訪問。謝謝你的幫助。我一遍又一遍地梳理代碼,並一直想念它。我也是GAS的新手,所以我沒有完全理解錯誤,現在實際上是有道理的。 – MarsMan

+0

哦,廢話 - 我看到「testRnage」,但認爲這是您在準備好帖子時的拼寫錯誤。杜,對不起。同時,我強烈建議你考慮使用JSON.stringify,你的代碼會變得更加清晰和簡單。 –