Using JavaScript, I have created a button with a function that fires when it is clicked. Three parameters are being passed to the function id
, clientid
, and title
. All are strings. Using the first method which can be demonstrated by clicking the Demo1 button, I receive an error of
"Expected ')'"
Using the second method which can be demonstrated by clicking the Demo2 button, I can successfully fire the function, however the log reads as if it is expecting 5 parameters rather than 3.
//console.log(id, clientid, title);
10636,8154,New Opportunity - 1926 Grand Avenue, LLC 5/22/2018 undefined undefined
//console.log(title)
undefined
What can I do to properly pass in title
?
(function() {
var id = "10636";
var clientid = "8154";
var title = "New Opportunity - 1926 Grand Avenue, LLC 5/22/2018";
console.log('<button style="background-color: #00539B; border: 1px solid #00539B; color: white; border-radius: 4px;" onclick="openAddModal(\'' + id + ',' + clientid + ',' + title + '\')" />' + id + "</button>");
document.getElementById("demo1").innerHTML = "<button style='background-color: #00539B; border: 1px solid #00539B; color: white; border-radius: 4px;' onclick=openAddModal(" + id + ',' + clientid + ',' + title + ")>" + 'Demo1' + "</button>"
document.getElementById("demo2").innerHTML = '<button style="background-color: #00539B; border: 1px solid #00539B; color: white; border-radius: 4px;" onclick="openAddModal(\'' + id + "," + clientid + "," + title + '\')" />' + 'Demo2' + "</button>"
})();
function openAddModal(id, clientid, title) {
console.log(id, clientid, title);
console.log(title);
}
<span id="demo1"></span>
<span id="demo2"></span>