Title: Calling A JavaScript Function On Or Before Form Submission?
Last modified: September 6, 2021

---

# Calling A JavaScript Function On Or Before Form Submission?

 *  Resolved [Windurin](https://wordpress.org/support/users/windurin/)
 * (@windurin)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/calling-a-javascript-function-on-or-before-form-submission/)
 * Hi. This is a rather unique case but I’m developing a sort of bookmark feature
   for my site. Chapter Bookmark is a CPT for which I have a create post ACFE form.
 * I’ve found code that allows me to insert highlighted text into my ACF textarea
   field on the form on button click using a JS function. This is the code I’m using:
 * [https://snippi.com/s/kf2uvvr](https://snippi.com/s/kf2uvvr)
 * And you can see it in action in a short video here:
 * But ideally I’d like to do this action without a button click and perhaps call
   the function after finishing highlighting the text. Is there some solution to
   getting this functionality?
 * For example, calling the function and inserting the text on form submission or
   perhaps before submission since it may not be inserted early enough? Failing 
   this, even having a button within the form itself that calls the function and
   inserts the currently selected text.
 * I know how to call PHP functions on form submission but I’m not sure if/how it
   can be done with JS.
 * Appreciate any help you can provide. Thanks.

Viewing 1 replies (of 1 total)

 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/calling-a-javascript-function-on-or-before-form-submission/#post-14844679)
 * Hello,
 * Thanks for the feedback!
 * You can perform an action after the form validation (and before its submission)
   using the native ACF JS hook `validation_complete`. [See documentation](https://www.advancedcustomfields.com/resources/javascript-api/#filters-validation_complete).
 * If you need to perform an action after the form submission (when the page has
   been reloaded), then you can use the `acfe/form/submit/success` JS hook (which
   is specific to ACFE Forms). [See documentation](https://www.acf-extended.com/features/modules/dynamic-forms/form-hooks#javascript-success).
 * You can also add a button within the form using the [ACFE Button Field](https://www.acf-extended.com/features/fields/button)
   and add your own JS logic using the [ACF JS API](https://www.advancedcustomfields.com/resources/javascript-api/#actions-new_field).
 * Hope it helps!
 * Have a nice day!
 * Regards.

Viewing 1 replies (of 1 total)

The topic ‘Calling A JavaScript Function On Or Before Form Submission?’ is closed
to new replies.

 * ![](https://ps.w.org/acf-extended/assets/icon-256x256.png?rev=2071550)
 * [Advanced Custom Fields: Extended](https://wordpress.org/plugins/acf-extended/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/acf-extended/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/acf-extended/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-extended/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-extended/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-extended/reviews/)

## Tags

 * [ACF](https://wordpress.org/support/topic-tag/acf/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 1 reply
 * 2 participants
 * Last reply from: [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * Last activity: [4 years, 9 months ago](https://wordpress.org/support/topic/calling-a-javascript-function-on-or-before-form-submission/#post-14844679)
 * Status: resolved