2015-12-16 65 views
1

我試圖將下拉菜單選項傳遞給我的Javascript文件中的函數。這是有效的,但只要我點擊提交按鈕,下拉菜單選項就會被刪除,而我剩下一個空白的下拉菜單。 (這似乎只發生在它的谷歌腳本中的應用程序。)當調用函數時,下拉菜單選項消失

任何想法爲什麼發生這種情況?有沒有更好的方式與應用程序腳本做到這一點?

任何幫助將不勝感激。

function doSomething(){ 
 
var x = document.getElementById("API_key").value; 
 
document.getElementById("API_key").innerHTML = x; 
 

 
var subdomain =document.getElementById("subdomain").value; 
 
document.getElementById("subdomain").innerHTML = subdomain; 
 

 
var state = document.getElementById("stateSelect").value; 
 
document.getElementById("stateSelect").innerHTML = state; 
 

 
google.script.run.getInfo(x,subdomain,state); 
 

 
}
<!DOCTYPE html> 
 
<html> 
 
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> 
 
    <head> 
 
    <base target="_top"> 
 
    </head> 
 
    <body> 
 
    
 
    <P ALIGN=Center> 
 

 
<BLOCKQUOTE> 
 
    
 
    
 
<P ALIGN=Left> 
 
    <div class="inline form-group"> 
 
     <label for="API_key">API Key</label> 
 
     <input type="text" id="API_key" style="width: 150px;" value="Enter API key here!"> 
 
    </div> 
 
    
 
    
 
    <P ALIGN=Left> 
 
    <div class="inline form-group"> 
 
     <p> 
 
     <label for="Subdomain">Subdomain</label> 
 
     <input type="text" id="subdomain" style="width: 150px;"> 
 
     </p> 
 
    </div> 
 
    
 
<select id ="stateSelect"> 
 
    <option value="">All</option> 
 
    <option value="&state=active">Active</option> 
 
    <option value="&state=past_due">Past Due</option> 
 
    <option value="&state=canceled">Canceled</option> 
 
    <option value="&state=expired">Expired</option> 
 
    <option value="&state=trialing">Trialing</option> 
 
</select> 
 
    
 
<div> 
 
    <input type="checkbox" id="Product Info" checked> 
 
    <label for="Product Info">Product Info</label> 
 
</div> 
 
    
 
<div> 
 
    <input type="checkbox" id="Shipping Info"> 
 
    <label for="Shipping Info">Shipping Info</label> 
 
</div> 
 
    
 
    
 
    <div> 
 
    <p> 
 
    <input class="action" type="button" onclick="doSomething()" value="Get Info!" /> 
 
    </p> 
 
    </div> 
 
    </BLOCKQUOTE> 
 
    </body> 
 
</html>

回答

0

function doSomething(){ 
 
var x = document.getElementById("API_key").value; 
 

 

 
var subdomain =document.getElementById("subdomain").value; 
 

 

 
var state = document.getElementById("stateSelect").value; 
 
    
 
    
 

 
google.script.run.getInfo(x,subdomain,state); 
 

 
}
<!DOCTYPE html> 
 
<html> 
 
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> 
 
    <head> 
 
    <base target="_top"> 
 
    </head> 
 
    <body> 
 
    
 
    <P ALIGN=Center> 
 

 
<BLOCKQUOTE> 
 
    
 
    
 
<P ALIGN=Left> 
 
    <div class="inline form-group"> 
 
     <label for="API_key">API Key</label> 
 
     <input type="text" id="API_key" style="width: 150px;" value="Enter API key here!"> 
 

 
    </div> 
 
    
 
    
 
    <P ALIGN=Left> 
 
    <div class="inline form-group"> 
 
     <p> 
 
     <label for="Subdomain">Subdomain</label> 
 
     <input type="text" id="subdomain" style="width: 150px;"> 
 

 
     </p> 
 
    </div> 
 
    
 
<select id ="stateSelect"> 
 
    <option value="">All</option> 
 
    <option value="&state=active">Active</option> 
 
    <option value="&state=past_due">Past Due</option> 
 
    <option value="&state=canceled">Canceled</option> 
 
    <option value="&state=expired">Expired</option> 
 
    <option value="&state=trialing">Trialing</option> 
 
</select> 
 

 
    
 
<div> 
 
    <input type="checkbox" id="Product Info" checked> 
 
    <label for="Product Info">Product Info</label> 
 
</div> 
 
    
 
<div> 
 
    <input type="checkbox" id="Shipping Info"> 
 
    <label for="Shipping Info">Shipping Info</label> 
 
</div> 
 
    
 
    
 
    <div> 
 
    <p> 
 
    <input class="action" type="button" onclick="doSomething()" value="Get Info!" /> 
 
    </p> 
 
    </div> 
 
    </BLOCKQUOTE> 
 
    </body> 
 
</html>

+0

刪除你在哪裏assinging價值的innerHTML的第二行同一個ID,你無線會得到null.Thats爲什麼它是刪除值。 –

0

這是沒有必要的。只是評論,並檢查它

function doSomething(){ 
    var x = document.getElementById("API_key").value; 
    document.getElementById("API_key").innerHTML = x; 

    var subdomain =document.getElementById("subdomain").value; 
    document.getElementById("subdomain").innerHTML = subdomain; 

    var state = document.getElementById("stateSelect").value; 
//document.getElementById("stateSelect").innerHTML = state; 

    google.script.run.getInfo(x,subdomain,state); 

}