Streaming live at 10am (PST)

Help me with an onClick snippet?

Hi, I found this thread that shows a method to enable adding an onClick event to a Webflow element: Add onClick attribute to any element with this JS snippet

Seems simple enough, and as far as I can see, I set it up right. But obviously not because it’s not working and I can’t seem to figure it out.

I’m adding it to a button, in order to trigger a Calendly embed popup.

Calendly had me add a snippet to the page, which I did. Then Calendly instructed me to trigger some additional code onClick, which I’m using the above method for.

Calendly instructions: https://help.calendly.com/hc/en-us/articles/360019861794-Common-embed-questions#2

Any help would be greatly appreciated, I promise I’ve worked on it for a while, and just can’t seem to get it working.

Here’s my read-only link: Webflow - EVOLVEXGUARDDIGITAL

Thanks a bunch.

Hey, @jackwabbit try pasting your whenClicked script Before </body> tag and can you add your published .io link so that we can look.

1 Like

Hi Sachin, thanks for replying! So move this script:

<script>
    window.onload = function() {
        var anchors = document.getElementsByTagName('*');
        for(var i = 0; i < anchors.length; i++) {
            var anchor = anchors[i];
            anchor.onclick = function() {
                code = this.getAttribute('whenClicked');
                eval(code);   
            }
        }
    }
</script>

from the head section to the"Before tag"? section?

Or did you mean the Calendly script that I current have in the attribute section of the button element?

If you’re talking about the script I have in the attribute section, if I added that before the /body section, would I need to target the button too? With something like this?:

document.getElementById("cta").onClick ='Calendly.showPopupWidget('https://calendly.com/jacksbusiness/15min');return false;';

And here is the .io link: https://evolvexguarddigital.webflow.io/

Sorry for my slow response, stepped away to eat some dinner.

Hi community. Shameless bump :sweat_smile:

I think I made it a bit confusing in my reply to @Sachin sorry for that.

Anybody else have any ideas on how I might be able to get what I described in the original post working?

@benavnon not sure if you’re still active on the forum or not, but do you know if the method in your thread I linked to in OP is still working?

Hey got it working. Had to remove return false; from the end of the Calendly snippet.