Isaac Paulsen
Isaac Paulsen

Reputation: 1

Need to get data from google spreadsheet to javascript to tie to button

I am very new to javascript... I am trying to fetch a url out of a cell in a Google spreadsheet, I would like that url to then be tied to a button on my site...(see button in html below)

"<center><FORM METHOD="LINK" ACTION= X
<INPUT TYPE="submit" VALUE="Clickable Button">
</FORM> </center>"

I would like the X variable too = the url contain in the specific cell in the Google spreadsheet. I have been searching for days to accomplish this, and I know I need to use some javascript but not sure how to implement it. Please help.

Upvotes: 0

Views: 417

Answers (1)

dev
dev

Reputation: 4009

One way you could achieve this is to use Google JSON API method as documented on this page.

You first add a javascript file to your page as the below example.

<script src="http://spreadsheets.google.com/feeds/list/*ID*/*WS*/public/values?alt=json-in-script&amp;callback=*FN*"></script>

• Where *ID* is the spreadsheet's long ID.

• Where *WS* is the worksheet number e.g. 1,2,3 etc.

• Where *FN* is the function you want to call.

Then in the callback function you can do something like the below to add your variable as desired. rowWithURL is the row number. CellWIthURL is usually the column heading. Or you could use some other methods to locate your URL.

function CallBack(json){
   entry = json.feed.entry[rowWithURL];
   url = entry.gsx$CellWithURL.$t;

   content = '<center>' + 
                 '<form method="link" action='+ url +'>' + 
                     '<input type="submit" value="Clickable Button">' +
                 '</form>' +
             '</center>'
}

Please note the above is not tested but should get you on the right track.

Upvotes: 2

Related Questions