I have a radiobuttongroup with three options. If user selects option 3, I want to expand a box on the page.
I’m trying to write an if statement in an on change event, so that the box expands if option 3 is selected, but stays collapsed with the two other options. How do I identify which option is selected with code?
Current code:
export function radiobuttongroup1_change(event) {
if ($w(‘#box’).collapsed) {
@lillewill , this will execute the expand/collapse code only when the index of the radiogroup is 3. Keep in mind that 0 is the first option, 1 is the second option index, and so on.
export function radiobuttongroup1_change(event) {
if ($w('#radiobuttongroup1').selectedIndex = 3 {
if ($w('#box').collapsed) {
$w('#box').expand();
} else {
$w('#box').collapse();
}
}
}
@lillewill Sorry, I should have tested it. There are a couple syntax issues: 1) it needs a parenthesis after the 3 and 2) there should be a triple equals sign signifying that it is a conditional expression and not an assignment:
export function radiobuttongroup1_change(event) {
if ($w('#radiobuttongroup1').selectedIndex === 3) {
if ($w('#box').collapsed) {
$w('#box').expand();
} else {
$w('#box').collapse();
}
}
}
@tony-brunsman Awesome it works! The third option expands the box now which is what I want. But when I click the other options, the box continues to be expanded, but they should then collapse. Any idea?