JS function to populate events