Hi, I am having issues with on onChange event with a dropdown. The dropdown has 3 options. Duplex, Triplex, and Fourplex. The user inputs are in groups for each choice as Unit 1, Unit 2, Unit 3, and Unit 4.
When Duplex is selected I would like Unit 1 group, and Unit 2 Group to show, and Unit 3 and 4 to collapse.
When Triplex is selected Unit 1, Unit 2, and Unit 3 groups should show and Unit 4 collapse.
When Fourplex is selected all groups show.
Here is the code I have below. Any help is greatly appreciated.
export function dropdown4_change ( event ) { if ( $w ( ‘#dropdown4’ ). value === ‘duplex’ )
$w ( ‘#group37’ ). show ();
$w ( “#group38” ). show ();
$w ( “#group31” ). collapse ();
$w ( “#group32” ). collapse (); if ( $w ( ‘#dropdown4’ ). value === ‘triplex’ )
$w ( ‘#group37’ ). show ();
$w ( “#group38” ). show ();
$w ( “#group31” ). show ();
$w ( “#group32” ). collapse (); if ( $w ( ‘#dropdown4’ ). value === ‘duplex’ )
$w ( ‘#group37’ ). show ();
$w ( “#group38” ). show ();
$w ( “#group31” ). show ();
$w ( “#group32” ). show ();
}
@miguelbuyme
Is there more CODE in your on your page? If so → show your whole code.
You are using → exportfunction dropdown4_change ( event ){ ← get rid of it.
Use another coding-technique. Also delete the button-connection inside the PROPERTY-PANEL!
COPY and PASTE the whole shown code to your page and run it again.
Hi @miguelbuyme , Can you post your latest code? Another thing to check is that the values in dropdown4 are exactly the same as the values in the code without any capitalization.
@miguel.buyme The original code works fine with just the first “if” statement. The provided if else-solution is not right and can’t work in your case, since the code will stop after entering the first → true-value.
→ get rid of → else if → use just → if + else
This way, every if-statement will be checked!
Edit: correction → it doesn’t matter which one is used, both should work.
@robmich Another thing to check is that the values in dropdown4 are exactly the same as the values in the code without any capitalization.
This answer from Miguel should tell us that the used values are correct… The original code works fine…
I guess the problem will be, that Miguel did not copy and paste the whole code including → onReady()-code-part.
Using the following kind of coding-style is not the best idea …
But anyway it would be surely helpful if you would show us your current running code (in a code-block) and perhaps even the console-logs (as screenshot).
Thank you to everyone that replied. All you input was greatly appreciated. I figured it out. The following code works perfectly. The issue was very simple…duplex, triplex, and fourplex only needed to be capitalized (Duplex, Triplex, Fourplex). See below. Hope this helps out some other wix users. Love this community.
export function dropdown4_change ( event ) { if ( $w ( ‘#dropdown4’ ). value === ‘Duplex’ ) {