<solved>Show/hide text based on if statement

Hi All,
I am building an RSVP form and based on attendance, the number of adults and children I want to hide/show certain fields.
The if statement does not seem to work when I select any of the else if options.

This is my whole code - I have tried everything under the sun. Do you see any error?
I have tried building it bit by bit and it all start going wrong as soon as I input multiple conditions in the if statement and else if

export function yesNoRadio_onChange(event) {
 var Attendance = Number($w('#yesNoRadio').value);// yes = 1, no = 0 
    console.log(Attendance);
}
export function adultNo_onChange(event) {
 var NoAdults = Number($w('#adultNo').value);//options:1, 2 
    console.log(NoAdults); 
}
export function childrenNo_onChange(event) {
 var NoChildren = Number($w('#childrenNo').value);//options:0,1,2,3,4
    console.log(NoChildren);
}
export function next1_onClick(event) {
 var Attendance = Number($w('#yesNoRadio').value);
 var NoAdults = Number($w('#adultNo').value);
 var NoChildren = Number($w('#childrenNo').value);
 if (Attendance === 0){
        $w("#slideshow1").changeSlide(3);
        } else if (NoAdults === 1 || NoChildren === 0 || Attendance === 1) {
        $w("#slideshow1").changeSlide(1);
        $w('#nameAdult2').hide();
        $w("#childernText").hide();         
        } else if (NoAdults === 2 || NoChildren === 0 || Attendance === 1) {
        $w("#slideshow1").changeSlide(1);
        $w('#nameAdult2').show();
        $w("#childernText").hide(); 
        } else if (NoAdults === 2 || NoChildren > 0 || Attendance === 1) {
        $w("#slideshow1").changeSlide(1);
        $w('#nameAdult2').show();
        $w("#childernText").show(); 
        } else if (NoAdults === 1 || NoChildren > 0 || Attendance === 1) {
        $w("#slideshow1").changeSlide(1);
        $w('#nameAdult2').hide();
        $w("#childernText").show(); 
        } 
}   

Thank you in advance to anyone who can assist

Letizia

Replace all or || with and &&

…and you can remove Attendance === 1 in every else if state, because it’s reduntant, then of course you have Attendance === 1 , or you would have Attendance === 0 and that you have in the first if-clausel. You understand the logic?

2 Likes

I can’t believe it… I tried at some point && and it was causing an error. It is now working.
I really cannot thank you enough!!!

Thank you - I will remove it.
I got overly paranoid that not all conditions would be captured so I was repeating all the three conditions at all times.

Great! Nice to hear it works :slight_smile: