{"id":157,"date":"2024-05-28T10:58:21","date_gmt":"2024-05-28T14:58:21","guid":{"rendered":"https:\/\/htmlformsplugin.test\/?p=157"},"modified":"2024-05-31T11:40:34","modified_gmt":"2024-05-31T15:40:34","slug":"javascript-events","status":"publish","type":"post","link":"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/","title":{"rendered":"JavaScript Events"},"content":{"rendered":"\n<p><a href=\"https:\/\/htmlformsplugin.com\/\">HTML Forms<\/a> fires several JavaScript events when visitors interact with a form on your site. You can hook into these events to run your own code, for example to send events to Google Analytics.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Available Events<\/h2>\n\n\n\n<p>The following events are available:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"submit\">submit<\/h3>\n\n\n\n<p>Fires right after the form is submitted, but before the request is processed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"submitted\">submitted<\/h3>\n\n\n\n<p>Fires after the request is processed, for both successful submissions and errors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"error\">error<\/h3>\n\n\n\n<p>Fires after the request is processed when a validation error occurs, for example, when a required field is missing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"success\">success<\/h3>\n\n\n\n<p>Fires after the request is processed, and the submission was a success.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hooking Into an Event<\/h2>\n\n\n\n<p>The following code example hooks into the &#8220;success&#8221; event for all forms (see above).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"\" class=\"\">&lt;script&gt;\nhtml_forms.on('success', function(formElement) {\n   \/\/ your code goes here\n});\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p>Alternatively, you can hook into a specific form using the default browser events API too.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"\" class=\"\">&lt;script&gt;\ndocument.querySelector('.hf-form-5').on('hf-success', function(e) {\n   \/\/ your code goes here\n});\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p>You can add this code directly to your form mark-up or to any other JavaScript file that is loaded on your site.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTML Forms executes a handful of custom JavaScript events based on user interactions. You can hook into these to run your own code.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[6],"class_list":["post-157","post","type-post","status-publish","format-standard","hentry","category-kb","tag-advanced"],"yoast_head":"<title>JavaScript Events - HTML Forms WordPress Plugin<\/title>\n<meta name=\"description\" content=\"HTML Forms executes a handful of custom JavaScript events based on user interactions. You can hook into these to run your own code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Events\" \/>\n<meta property=\"og:description\" content=\"HTML Forms executes a handful of custom JavaScript events based on user interactions. You can hook into these to run your own code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/\" \/>\n<meta property=\"og:site_name\" content=\"HTML Forms WordPress Plugin\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-28T14:58:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-31T15:40:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/htmlformsplugin.com\/wp-content\/uploads\/2024\/05\/open-graph-html-forms.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"JavaScript Events\" \/>\n<meta name=\"twitter:description\" content=\"HTML Forms executes a handful of custom JavaScript events based on user interactions. You can hook into these to run your own code.\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/javascript-events\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/javascript-events\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#\\\/schema\\\/person\\\/91bdb8fe3d28e069afcaa14af31ce932\"},\"headline\":\"JavaScript Events\",\"datePublished\":\"2024-05-28T14:58:21+00:00\",\"dateModified\":\"2024-05-31T15:40:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/javascript-events\\\/\"},\"wordCount\":158,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#organization\"},\"keywords\":[\"Advanced\"],\"articleSection\":[\"Knowledge Base\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/javascript-events\\\/\",\"url\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/javascript-events\\\/\",\"name\":\"JavaScript Events - HTML Forms WordPress Plugin\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#website\"},\"datePublished\":\"2024-05-28T14:58:21+00:00\",\"dateModified\":\"2024-05-31T15:40:34+00:00\",\"description\":\"HTML Forms executes a handful of custom JavaScript events based on user interactions. You can hook into these to run your own code.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/javascript-events\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/javascript-events\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/javascript-events\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/htmlformsplugin.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript Events\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#website\",\"url\":\"https:\\\/\\\/htmlformsplugin.com\\\/\",\"name\":\"HTML Forms WordPress Plugin\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/htmlformsplugin.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#organization\",\"name\":\"HTML Forms WordPress Plugin\",\"url\":\"https:\\\/\\\/htmlformsplugin.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/htmlformsplugin.com\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/html-forms-logo.png\",\"contentUrl\":\"https:\\\/\\\/htmlformsplugin.com\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/html-forms-logo.png\",\"width\":256,\"height\":256,\"caption\":\"HTML Forms WordPress Plugin\"},\"image\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#\\\/schema\\\/person\\\/91bdb8fe3d28e069afcaa14af31ce932\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/htmlformsplugin.com\"],\"url\":\"https:\\\/\\\/htmlformsplugin.com\\\/author\\\/admin\\\/\"}]}<\/script>","yoast_head_json":{"title":"JavaScript Events - HTML Forms WordPress Plugin","description":"HTML Forms executes a handful of custom JavaScript events based on user interactions. You can hook into these to run your own code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Events","og_description":"HTML Forms executes a handful of custom JavaScript events based on user interactions. You can hook into these to run your own code.","og_url":"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/","og_site_name":"HTML Forms WordPress Plugin","article_published_time":"2024-05-28T14:58:21+00:00","article_modified_time":"2024-05-31T15:40:34+00:00","og_image":[{"width":1200,"height":600,"url":"https:\/\/htmlformsplugin.com\/wp-content\/uploads\/2024\/05\/open-graph-html-forms.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_title":"JavaScript Events","twitter_description":"HTML Forms executes a handful of custom JavaScript events based on user interactions. You can hook into these to run your own code.","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/#article","isPartOf":{"@id":"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/"},"author":{"name":"admin","@id":"https:\/\/htmlformsplugin.com\/#\/schema\/person\/91bdb8fe3d28e069afcaa14af31ce932"},"headline":"JavaScript Events","datePublished":"2024-05-28T14:58:21+00:00","dateModified":"2024-05-31T15:40:34+00:00","mainEntityOfPage":{"@id":"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/"},"wordCount":158,"commentCount":0,"publisher":{"@id":"https:\/\/htmlformsplugin.com\/#organization"},"keywords":["Advanced"],"articleSection":["Knowledge Base"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/","url":"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/","name":"JavaScript Events - HTML Forms WordPress Plugin","isPartOf":{"@id":"https:\/\/htmlformsplugin.com\/#website"},"datePublished":"2024-05-28T14:58:21+00:00","dateModified":"2024-05-31T15:40:34+00:00","description":"HTML Forms executes a handful of custom JavaScript events based on user interactions. You can hook into these to run your own code.","breadcrumb":{"@id":"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/htmlformsplugin.com\/kb\/javascript-events\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/htmlformsplugin.com\/kb\/javascript-events\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/htmlformsplugin.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript Events"}]},{"@type":"WebSite","@id":"https:\/\/htmlformsplugin.com\/#website","url":"https:\/\/htmlformsplugin.com\/","name":"HTML Forms WordPress Plugin","description":"","publisher":{"@id":"https:\/\/htmlformsplugin.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/htmlformsplugin.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/htmlformsplugin.com\/#organization","name":"HTML Forms WordPress Plugin","url":"https:\/\/htmlformsplugin.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/htmlformsplugin.com\/#\/schema\/logo\/image\/","url":"https:\/\/htmlformsplugin.com\/wp-content\/uploads\/2024\/05\/html-forms-logo.png","contentUrl":"https:\/\/htmlformsplugin.com\/wp-content\/uploads\/2024\/05\/html-forms-logo.png","width":256,"height":256,"caption":"HTML Forms WordPress Plugin"},"image":{"@id":"https:\/\/htmlformsplugin.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/htmlformsplugin.com\/#\/schema\/person\/91bdb8fe3d28e069afcaa14af31ce932","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/htmlformsplugin.com"],"url":"https:\/\/htmlformsplugin.com\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/posts\/157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/comments?post=157"}],"version-history":[{"count":2,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/posts\/157\/revisions"}],"predecessor-version":[{"id":167,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/posts\/157\/revisions\/167"}],"wp:attachment":[{"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/media?parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/categories?post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/tags?post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}