I am currently trying to create an onclick event for a button that calls a separate function and passes uses an object as the parameter for this function.
My code can be seen below:
async function getJourneyAwait(){
const routes = await getJourney();
var innerHTML = " ";
if(!(routes === null)) {
for (var i = 0; i < routes.length; i++){
console.log(routes[i])
console.log(typeof(routes[i]))
var route = routes[i]
innerHTML += '<p> Route ' + i+1 + ': <button onClick=startJourney(' + route + ')>Start Trip</button></p>'
}
document.getElementById('tripmessage').innerHTML = innerHTML;
}
}
function startJourney(route){
console.log(route);
}
When I try to click the Start Trip button I get an error stating: Uncaught SyntaxError: Unexpected end of input at .(index):1
When I inspect the button element it there seems to be some kind of error with the parameter as the element is as follows:
<button onclick="startJourney([object" object])="">Start Trip</button>
I have tried multiple different ways and in some cases I have been able to get the function to run but when I do all that is logged to the console is undefined. For example, if I remove the plus signs and quotes on either side of 'route' the function runs but undefined is logged to the console.