How to Make Scripts Run On Button Click

Video Tutorial:

Article:

Adding scripts gives your site extra functionality. When you add a script at page level, you can add a button users can click to activate that script. Here’s how.

  1. In the Page Builder, click on Page in the top toolbar, then click on Custom Scripts.
  2. Click the Page tab, then click Add Page Script. Give your script a name (this is important: it allows your script to be targeted by Actions and Events).
  3. Add a description, and switch the script runs on page load toggle to Off.
  4. Next, choose the script position. If you are unsure where to put it, choose Body.
  5. Paste the code of your script into the box, and click Save.

Your script will be added, and a small red indicator will remind you that you need to republish your page(s) before you see the changes.

Next, we’ll add a button and make it trigger the script when clicked.

  1. In the Elements tray, click Form Elements and drag a Submit button onto your page. In the Button Settings tab of the Properties panel, set the button mode to Trigger.
  2. After that, click the Add an Action button.

  1. Then, click Add New Action

  1. Set up a new action with the following settings:

a. Event > Click > On click

  • b. Action > Script > Run target script

    c. Target > Choose your script from the dropdown list

    Click Done.


Now when you publish this page, a click on this button will run your script.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us