I want to show/hide four form fields when a specific option is chosen in an option Group in the start of the form - and I have written this code:
$w.onReady(function () {
//TODO: write your page related code here…
//this hides the input box when page is first shown
//either hide and disable or just one of them
$w(“#input9”).hide();
$w(“#input9”).disable();
$w(“#input10”).hide();
$w(“#input10”).disable();
$w(“#input11”).hide();
$w(“#input11”).disable();
$w(“#input12”).hide();
$w(“#input12”).disable();
});
export function radioGroup1_change1(event) {
//Add your code for this event here:
let selectedIndex = $w(“#radioGroup1”).selectedIndex;
// a text for debugging purpose, showing the index number of selected option (started from 0)
$w(“#text13”).text="selected index is "+selectedIndex;
//if 3rd option selected
if (selectedIndex === 2) {
// debug message
$w(“#text13”).text=“into if loop of 3rd option selected”;
//debug message
$w(“#text13”).text=“into else of if loop of 1st/2nd option selected”;
//either hide and disable or just one of them
$w(“#input9”).hide();
$w(“#input9”).disable();
$w(“#input10”).hide();
$w(“#input10”).disable();
$w(“#input11”).hide();
$w(“#input11”).disable();
$w(“#input12”).hide();
$w(“#input12”).disable();
}
}
It works fine in the start of the code…the four fields are hidden as they should - BUT when I chose the option that should SHOW the four fields NOTHING happens.
Annother thing: My Code Editor states that I should use three “=” signs in the If sentence “if (selectedIndex === 2)” and not just two as written in your code - but it’s not do any difference if I use two or three equal signs.
Can someone please help me solve the problem - thanks in advance…
First off, if you are going to do all this, then you are much better just making up your own user input form yourself in Wix and using the code to make it all happen, as that way you can have complete control over everything that happens and what you do with it. https://support.wix.com/en/article/creating-a-form-with-user-input-elements
Not saying that Wix Forms app is not to be used, however that is more for people who want it all done for them and not really have to code anything themselves.
Note that there is a difference between the hide function and the collapse function, where hide just hides it on the page and it still takes up space, whereas collapse removes it from the page and it doesn’t take up any space, which is stated in the info as well.
@givemeawhisky Many many thanks for your outstandig answer and help - I’m allready a good bit futher, thanks to the refferences you har provided me with