Switcher for 2 html iframe

Good morning,

Here’s my worry. I’m not a developer and I’m just getting started with the new Wix Code features, so be nice :wink:

I would like to display two iframe html elements, linked to a “swticher”.
When the switch is on the left, one of the elements is shown. When the switch is on the right, the other element is displayed and the first disappears. Obviously, we must be able to repeat the operation.

What exactly do I have to do? What code do I have to put.

let’s say the swith has the name “switch1”
and the elements “html1” & “html2”

Onclick event? Code?

Thanks in advance for your help!

Sincerely

Ben

You can use a RadioButtonGroup with two radio buttons: left and right .


Perhaps arrange horizontally so that the buttons themselves will be on the left and the right:

Add an onChange() event handler to the RadioGroupButton like this to get your choice:

export function radioGroup1_change(event, $w) {
    //Add your code for this event here:
    let sel = $w("#radioGroup1").selectedIndex;
    console.log("change " + sel);
    if(sel === "left") {
        $w("#leftHtmlComponent").show();
        $w("#rightHtmlComponent").hide();
    }
    else {
        $w("#rightHtmlComponent").show();
        $w("#leftHtmlComponent").hide();
    }
}

Basically, you could use a Switch component since it’s designed for a binary choice: on/off, left/right. You would just need to add labels (text) to each side of the Switch to inform the user of your intentions. You would then use an onChange() event handler for the Switch and use the two possible answers of a switch to be left and right.

I hope this helps,

Yisrael