0

I've rendered a table using Jquery's DataTable library. Within this datatable I've rendered hyperlink anchors with an onclick event that calls a javascript function. I need to pass more than one parameter to these functions.

I'm able to pass one parameter to the function but I'm unable to pass the variables as two separate parameters. See below code. E.g The value of the GuestID parameter in the emailGuest function takes both GuestID and email e.g. 84a09eeb-9d8d-43cb-9719-e597fc5ad215,someone@site.com*

DataTable hyperlink render section

                    data: null, render: function (data, type, row )
                    {
                        return "<a href='#' class='btn btn-danger' onclick= DeleteData('" + row.id + "'); >Delete</a>";
                    }
                },
                {
                    data: null, render: function (data, type, row) {
                        return "<a href='#' class='btn  btn-default' onclick= emailGuest('" + row.id + ',' + row.email + "'); >Email</a>";
                    }
                },
            ]

        });
    });

emailGuest Function

   function emailGuest(GuestID,email) {
        $('#GuestEmail').modal('show');
        document.getElementById("emailID").value = GuestID;

        document.getElementById("emailAddress").value = email;

    }
dewit777
  • 25
  • 1
  • 6

1 Answers1

1

Your piece of code wrote both variables in one because you missed some ' in there (', ' changed to "', '"):

              data: null, render: function (data, type, row )
                {
                    return "<a href='#' class='btn btn-danger' onclick= DeleteData('" + row.id + "'); >Delete</a>";
                }
            },
            {
                data: null, render: function (data, type, row) {
                    return "<a href='#' class='btn  btn-default' onclick= emailGuest('" + row.id + "', '" + row.email + "'); >Email</a>";
                }
            },
        ]

    });
});
MauriceNino
  • 6,214
  • 1
  • 23
  • 60
  • Damn cannot believe that took me so long to figure out. I knew it had something to do with that. Thanks this solution fixed it. – dewit777 May 13 '19 at 13:57