I’m using eventbrite API to output events from an account. I have used a basic ajax to call the json into my website yet I’d like to jazz up the UI.
Ideally I want to output the event title and description into a modal (using bootstrap - like this https://codepen.io/stevan/pen/oJqvoN) but to do this I would need to use a unquie #ID for each modal. Can I do that via javascript?
console.dir(event);
s += "<div class='col-md-6 col-lg-4'>";
s += "<img src='" + event.logo.url + "'>";
s += "<h2><a href='" + event.url + "'>" + event.name.text + "</a></h2>";
s += "<p><b>Location: " + event.venue.address.address_1 + "</b><br/>";
s += "<b>Date/Time: " + eventTime + "</b></p>";
s += "<p>" + event.description.text + "</p>";
s += "</div>";
}
$events.html(s);
} else {
$events.html("<p>Sorry, there are no upcoming events.</p>");
}
});
You’re calling an API and getting a list of events as JSON. You posted some code which seems to indicate you are building one (or more) modals from the JSON.
How are you getting from calling the API to creating the modal? Could you post the code showing your Ajax call and what you’re doing with the response.
for (var i = 0; i < res.events.length; i++) {
var event = res.events[i];
var eventTime = moment(event.start.local).format('d/MM/YY h:mm A');
s += "<div class='col-md-6 col-lg-4' id='modal-" + id + "'>";
...
}
Although that is hard to read. So I would use a template string:
for (var i = 0; i < res.events.length; i++) {
var event = res.events[i];
var eventTime = moment(event.start.local).format('d/MM/YY h:mm A');
s += `<div class='col-md-6 col-lg-4' id='modal-${id}''>";
...
}
{
"description": {
"text": "Rozlyn Sheridan is one half of the hit comedy duo Nuala & Noleen.",
"html": "<P>Rozlyn Sheridan is one half of the hit comedy duo Nuala & Noleen.</P>"
},
"long_description": {
"text": null,
"html": null
},
"logo": null,
"resource_uri": "https://www.eventbriteapi.com/v3/organizers/18005188196/",
"id": "18005188196",
"name": "Rozlyn Sheridan, Newry.",
"url": "https://www.eventbrite.co.uk/o/rozlyn-sheridan-newry-18005188196",
"num_past_events": 0,
"num_future_events": 0,
"logo_id": null
}
Ideally I’d like the logo to be the image that when clicked on opens up the modal showing the title and description and a link to booking the event (url).