# Can you call an entire list within an OnEvent

**URL:** <https://forum.code.org/t/can-you-call-an-entire-list-within-an-onevent/36234>\
**Category:** Coding and Debugging Help\
**Created:** [April 26, 2022, 5:11pm UTC](https://forum.code.org/t/can-you-call-an-entire-list-within-an-onevent/36234 "2022-04-26T17:11:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesJohnson](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@JamesJohnson](https://forum.code.org/u/JamesJohnson)\
**Post date:** [April 26, 2022, 5:11pm UTC](https://forum.code.org/t/can-you-call-an-entire-list-within-an-onevent/36234/1 "2022-04-26T17:11:35Z")

</div>

//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”);  
});

> **[Check out what I made](https://studio.code.org/projects/applab/Uw50cITdLDdjei4Jr4WjjqR-UQ_6Z8dTUrABZ8FjOV4)**
>
> I wrote the code myself with Code.org

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.

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [April 27, 2022, 6:11pm UTC](https://forum.code.org/t/can-you-call-an-entire-list-within-an-onevent/36234/2 "2022-04-27T18:11:38Z")

</div>

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

[Single Event Linked to Multiple IDs](https://forum.code.org/t/single-event-linked-to-multiple-ids/15764/5)

Mike
