Help! trying to add an opt in check box

Hi there, I’ve been in touch with Wix support and Wix arena re this issue and no-one could help. What with GDPR looming, I’m trying to get my site all compliant… Which basically means adding an “opt in check box” next to my “subscribe now” button. I’ve added it and it works but a bit too well. I need for the “subscribe now” button to NOT work UNTIL they have ticked the opt in check box… any ideas? Many thanks knowledgeable peeps.

Hi Laura,
Add an Checkbox element, uncheck “Check by Default”.
Uncheck “Enable by default” field of the subscribe now button.
Create an event “onChange” to the Checkbox element and adapt this code to your page (ID):

export function yourCheckbox_change(event, $w) {
	const checkBoxValue = event.target.checked; // boolean field, true or false
	checkBoxValue ? $w('#subscribeNowButton').enable() : $w('#subscribeNowButton').disable(); 
} 

Good luck!
Roi

Please excuse my ignorance (I’m not a coder - but I’m learning! ) Where do I put my page ID?
I managed everything else i think
thanks
L

The same question from me…

And me!

Thought I would answer this since several folks have a problem with the answer.

When Roi stated

adapt this code to your page (ID).
What he was trying to say is that the subscribe now button may not be called $w(’ #subscribeNowButton '). subscribeNowButton is the ID of the button. If you haven’t changed the name of the button you are using then you probably need to use it’s default name (ID). When you add a button to a page it will likely be given the name button1. If you have many buttons they are given incrementing values, button1, button2, etc.

So you find the name (ID) of your button - say button3 and adapt the proposed code using the new name:

export function yourCheckbox_change(event, $w) {
    const checkBoxValue = event.target.checked;
    // boolean field, true or false
    checkBoxValue ? $w('#button3').enable() : $w('#button3').disable();
} 

Hope that helps