# Issues with Button::onClick and radio buttons

**URL:** <https://forum.juce.com/t/issues-with-button-onclick-and-radio-buttons/53874>\
**Category:** General JUCE discussion\
**Created:** [November 24, 2022, 5:21am UTC](https://forum.juce.com/t/issues-with-button-onclick-and-radio-buttons/53874 "2022-11-24T05:21:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcusonic](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Marcusonic](https://forum.juce.com/u/Marcusonic)\
**Post date:** [November 24, 2022, 5:21am UTC](https://forum.juce.com/t/issues-with-button-onclick-and-radio-buttons/53874/1 "2022-11-24T05:21:08Z")

</div>

I was confused with the behavior of the application until I realized that the current button in the “on” state also sends a click when it goes to the “off” state. Maybe this should be documented since it only refers to the clicked button. Although I think the ideal would be that in addition to onClick and onStateChange, there should be something like onDown or onToggleOn

So I finally solved it by checking the toggle state, however I have not been able to refer to the button itself since it is in an array, although it would be more useful to pass the index.

> for (int i=0;i\<4;i++) {  
> button[i].onClick = [this] () { bool bState = button[i].getToggleState(); // ERROR !!! };  
> }

so i have finally unrolled the loop, but this is not acceptable. What if there were 30 buttons?. what solution is there for this?

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [November 24, 2022, 2:35pm UTC](https://forum.juce.com/t/issues-with-button-onclick-and-radio-buttons/53874/2 "2022-11-24T14:35:31Z")

</div>

you can capture i

```auto

for (int i=0;i<4;i++) {
button[i].onClick = [this, i] () { bool bState = button[i].getToggleState(); // ERROR !!! };
}

```

---

<div class="post-metadata">

**Author:** ![Marcusonic](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Marcusonic](https://forum.juce.com/u/Marcusonic)\
**Post date:** [November 24, 2022, 10:33pm UTC](https://forum.juce.com/t/issues-with-button-onclick-and-radio-buttons/53874/3 "2022-11-24T22:33:25Z")

</div>

this is exactly what i was looking for, Thank you
