If Else - Unexpected Token (SOLVED)

I am very new to Wix code but I have created a custom RSVP form, which has a radio button group with 2 options with values being Attending and Not Attending.

If the user selects the option with the value Attending, when they click on the Submit button I want to redirect them to a separate Thank You page, likewise, if the user has selected the option with the value Not Attending I want to redirect them to a Sorry you cant make it page.

I have the following code, however, am getting an unexpected token error at Line 13. I suspect I have some bracketing and parenthesis wrong but after trying many different ways and searching for hours online for a solution, I just cannot find where I am going wrong.

Any assistance would be greatly appreciated. Thanks.

Greetings,

Import statements need to be at the top level, typically at the top of the page and definitely outside any event or method code.

There is no need to do a separate If “Not Attending” statement. The logic was already properly handled with the first “If”.

I’m wondering if you really want to put this code in the onReady event that executes after the page loads. The user/visitor would not have had a chance to make the Attending/Not Attending selection yet from radioGroup1, or did that happen in a previous page? If the selection is to made on this page, then you would want to put the code in an onChange event function of radioGroup1 and also have neither choice selected initially.


Then code it like this:

import wixlocation from ‘wix-location’;

export function radioGroup1_change(event) {
if ($w(‘#radioGroup1’).value === ‘Attending’){
wixlocation.to(“/yvonneandjosh-thankyou”);
} else {
wixlocation.to(“/yvonneandjosh-sorry”);
}
});

Hope this helps.

1 Like

Thanks Anthony B. I didnt realise I had the code on the OnReady function, I thought I had actually added it to the on click function of the submit button.

I’ll fix that up and give your code a crack. Thanks again. I’ll post how I get on.

Thanks anthonyb. Works perfectly!!! I amended the code to below on the onclick event of the submit button.

import wixlocation from ‘wix-location’;

export function button14_click(event) {
if ($w(‘#radioGroup1’).value === ‘Attending’){
wixlocation.to(“/yvonneandjosh-thankyou”);
} else {
wixlocation.to(“/yvonneandjosh-sorry”);
}
}