Search.../

onChoiceSelected( )

Adds an event handler that runs when a product option choice is selected.

Description

This function is currently only available for Wix Studio sites.

The onChoiceSelected() function adds an event handler that runs when a site visitor selects a product option choice such as {color: "white", size: "m"}.

The received selectedChoices object contains information about the product option choice that was selected.

Syntax

function onChoiceSelected(choiceSelectedEventhandler: choiceSelectedEventHandler): Promise<void>
choiceSelectedEventhandler: function choiceSelectedEventHandler(selectedChoices: Object): void

onChoiceSelected Parameters

NAME
TYPE
DESCRIPTION
choiceSelectedEventhandler

The function to run when a product option choice is selected.

Returns

Return Type:

Promise<void>

choiceSelectedEventHandler Parameters

NAME
TYPE
DESCRIPTION
selectedChoices
Object

An object with key:value pairs representing the selected product option choices. Each pair is a product option created in the Products tab of the dashboard. Each key corresponds to an option name, and its values correspond to the choices for this option. For example, {color: "white", size: "m"}.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

Get the product option choice that was selected

Copy Code
1$w('#myProductPage').onChoiceSelected( (selectedChoices) => {
2 let mySelectedChoices = selectedChoices; // {color: "blue", size: "m"}
3} );