javascripthubspot-api

Problem with my click element in Javascript


I can't make an alert in JS when clicking on the "Submit" button. It's html loaded remotely by a script and the JS can't recognize it.

Here is a reconstruction, anyone have an idea please? http://jsfiddle.net/sdrvqjxn/1/

<script charset="utf-8" type="text/javascript" src="//js-eu1.hsforms.net/forms/embed/v2.js"></script>
<script>
  hbspt.forms.create({
    region: "eu1",
    portalId: "26927362",
    formId: "46123717-093e-4314-9afb-d71fc6e2e40f"
  });
</script>

Solution

  • Set the onFormSubmit option:

    hbspt.forms.create({
        region: "eu1",
        portalId: "26927362",
        formId: "46123717-093e-4314-9afb-d71fc6e2e40f",
        onFormSubmit() {
            alert('submit');
        }
    });