2016-04-03 168 views
0

我需要電子表格查詢方面的幫助,可以從用戶輸入中設置搜索條件。我更改了電子表格密鑰,因爲它是機密信息,但如果我手動鍵入MY VARIABLE的實際數字(在CONTAINS%20%27之後顯示),代碼將起作用。如何從用戶輸入設置搜索條件?

我需要幫助的是將由用戶輸入的id代碼替換下面的查詢中的MY VARIABLE的代碼。誰能幫忙?

<input type='text' id='userInput' value='Enter Text Here' /> 
<input type='button' onclick='javascript:changeText2()' value='Click here after you enter your Skyward Password'/> 
Click on link to see your PRIDE info : <a href="https://spreadsheets.google.com/tq?tqx=out:html&tq=SELECT%20B%2C%20C%2C%20D%2C%20F%20WHERE%20D%20CONTAINS%20%27MY_VARIABLE%27&key=xxxxxgoogle spreadsheet keyFT7mL4DLX1xzeDsnzsbZG5jp4ZcWAOxU&gid=0" id=lnk>Click her for PRIDE info</a> <br> 

回答

0

第一:不使用JavaScript:

<input type='button' onclick='changeText2()' value='Click here after you enter your Skyward Password'/> 

它將輸出和錯誤,如果你寫:ID =油墨而不是ID = 「墨水」

Click on link to see your PRIDE info : <a href="" id="Ink">Click her for PRIDE info</a> <br> 

現在代碼:

function changeText2(){ 
    var ink = document.getElementById('Ink'); 
    ink.href = "https://spreadsheets.google.com/tq?tqx=out:html&tq=SELECT%20B%2C%20C%2C%20D%2C%20F%20WHERE%20D%20CONTAINS%20%27" +encodeURIComponent(document.getElementById('userInput').value)+ "%27&key=xxxxxgoogle spreadsheet keyFT7mL4DLX1xzeDsnzsbZG5jp4ZcWAOxU&gid=0" 
} 

encodeURIComponent用於轉義t他串。 簡單,還是?

+0

謝謝,可惜它沒有奏效。 這是我試圖嵌入示例電子表格的關鍵代碼。 function changeText2(){var ink = document.getElementById('Ink'); ink.href =「https://spreadsheets.google.com/tq?tqx=out:html&tq=SELECT%20B%2C%20C%2C%20D%2C%20F%20WHERE%20D%20CONTAINS%20%27」+ encodeURIComponent方法(的document.getElementById( 'userInput')。值)+ 「%27&鍵= 1LUkEwP-HEIFdYZSqwHvKgYHWqrP1f6rGXm0yLFlBE44&GID = 0」} https://docs.google.com/spreadsheets/d/1LUkEwP-HEIFdYZSqwHvKgYHWqrP1f6rGXm0yLFlBE44/edit#gid=127431008 – Mike

+0

以下是我的示例數據電子表格的鏈接。提前致謝。 https://docs.google.com/spreadsheets/d/1LUkEwP-HEIFdYZSqwHvKgYHWqrP1f6rGXm0yLFlBE44/edit#gid=127431008 – Mike

+0

也許我應該只描述我想要做什麼,看看是否有更好的方法來做到這一點。從我的谷歌網頁我想讓學生輸入他們的密碼,並有API語言查詢來創建一個HTML顯示只是他們從上面列出的示例網頁的信息。 – Mike