Loren Zimmer
Loren Zimmer

Reputation: 480

Parsing a button Id to a function

I've got a google script that creates a table within a webpage. In that script I'm attempting to create a button that passes it's ID to an HTML function. Here is a code snipit:

if (i != 0){

      returnTable = returnTable + "<td><button id="+'"'+data[i][9]+'"'+" onClick="+'"confirm_click(this.id)"'+">Confirm</button></td>";
      returnTable = returnTable + "<td><button id="+data[i][9]+" onClick="+'"deny_click(this.id)"'+">Deny</button></td>"
      Logger.log("data[i][9] is:  " + data[i][9]);
    } 

Data[i][9] is data(a unique ID Field) that is read from a google spreadsheet. The logger returns the right string, but when the following function is called when the button is clicked the console returns "undefined":

function confirm_click(buttonId){
    console.log(buttonID);
    }

Any guidance on what I'm doing wrong would be hugely helpful.

Thanks so much,

Loren

Upvotes: 0

Views: 63

Answers (1)

a2345sooted
a2345sooted

Reputation: 599

function confirm_click(buttonId) <--THIS VAR NAME {
  console.log(buttonID) <-- IS NOT THE SAME AS THIS VAR NAME;
}

notice buttonID =/= buttonId. Try making the variable names match and see if the problem persists.

Upvotes: 2

Related Questions