Button click does not work in live mode

Hello !

I am working on a custom registration form, it seems to work fine in preview mode but not in live mode. So, I decided to work on a very basic function and the problem remains.

I created a lightbox which contains text inputs and a button.
Here is the code :

$w.onReady( function () {
console.log(“Ready”);
console.log(“Button exists ?”, $w(“#button3”));

$w("#button3").onClick( (event) => { 
    console.log("HELLO !", event); 
    $w("#repId").value = "321"; 
}); 

});

#repId is an input text. #button3 is a simple button with no link.
When I preview the page and click on the button, everything is working. When I publish the page and click on the button, it does nothing.

Does anyone knows why ?
Thanks in advance !

Please explain what works and what doesn’t work. What do you expect to happen? What really happens? What is it supposed to do?

Here are 2 screenshots :


Thanks

dont You have any errors in code.
Did you add function onclick to button in property panel?

Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.

The lightbox’ name is “_inscription-simple”

Is that OK for you ? I added some comments in the code.

@hello95783 I got the Lightbox opened from the La Présentation page. It works fine.

@yisrael-wix It is called as soon as you want to access a members only page. So every pages except the first one. You can try accessing /accueil or /presentation and the lightbox will appear

@hello95783 Yes, I discovered that. I tried the Lightbox and as you can see in the screenshots it worked fine.

@yisrael-wix All right, I just figured out it is working when I access correctly to the page (ie. by clicking on the link in the home page named “Entrer sur le site”) on my friend’s computer. When I try to access to a protected page directly, the event doesn’t seem to fire.
Sometimes, the lightbox appears but we don’t see the underlying page (blank).

It may be on problem between the chair and the keyboard :wink: So I am going to move forward and get back at you later if needed.

Do you recommend to wait for $w.onReady() to activate the action buttons ?

Thanks a lot for your time,

@hello95783 Glad you got it figured out (as such) so far.

As far as do I recommend to wait for $w.onReady(), not sure what you mean. But, you can’t perform actions on components outside of the onReady() or other event handlers.