Can you call an entire list within an OnEvent

//list//
var wrngbtns5 = [“bs5rd1c”, “bs5rd1a”, “bs5rd3a”, “bs5rd5”, “bs5rd6b”];

//What I do Now//
onEvent(wrngbtns5[0],“click”, function() {
showElement(“ws5”);
showElement(“btnts5”);
});
onEvent(wrngbtns5[1],“click”, function() {
showElement(“ws5”);
showElement(“btnts5”);
});
onEvent(wrngbtns5[2], “click”, function() {
showElement(“ws5”);
showElement(“btnts5”);
});
onEvent(wrngbtns5[3], “click”, function() {
showElement(“ws5”);
showElement(“btnts5”);
});
onEvent(wrngbtns5[4], “click”, function() {
showElement(“ws5”);
showElement(“btnts5”);
});

I except all my wrong buttons located in the list to be placed within one ‘OnEvent’ to make code more concise. So when I press on any of the buttons, Incorrect and a Try Again button is displayed.

Sometimes an error, “wrngbtns5” is not a string. If separated like this onEvent(wrngbtns5[0,1,2,3,4] only the last one (4) is accessed.

//Separate with commas and brackets//
onEvent(wrngbtns5[0],[1],[2],[3],[4] “click”, function() {
showElement(“ws5”);
showElement(“btnts5”);

//Calling the list name//
onEvent(wrngbtns5, “click”, function() {
showElement(“ws5”);
showElement(“btnts5”);

Also using a ‘or’ Boolean has been unsuccessful.

Here’s a thread on this topic with a few workarounds that should accomplish what you are after.

Single Event Linked to Multiple IDs

Mike

1 Like