# Gform\_submit\_button Append Javascript example throws error \[RESOLVED\]

**URL:** <https://community.gravityforms.com/t/gform-submit-button-append-javascript-example-throws-error-resolved/14811>\
**Category:** Get Help\
**Tags:** javascript, gform\_submit\_button\
**Created:** [March 28, 2023, 3:52pm UTC](https://community.gravityforms.com/t/gform-submit-button-append-javascript-example-throws-error-resolved/14811 "2023-03-28T15:52:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex.tocco88](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@alex.tocco88](https://community.gravityforms.com/u/alex.tocco88)\
**Post date:** [March 28, 2023, 3:52pm UTC](https://community.gravityforms.com/t/gform-submit-button-append-javascript-example-throws-error-resolved/14811/1 "2023-03-28T15:52:46Z")

</div>

I’m adding the example code found here: [https://docs.gravityforms.com/gform\_submit\_button/#h-4-append-a-javascript-action-to-the-button](https://docs.gravityforms.com/gform_submit_button/#h-4-append-a-javascript-action-to-the-button) to my functions.php page on my wordpress site but the code changes throw an error on   
$dom-\>loadHTML( ‘\<?xml encoding=“utf-8” ?\>’ . $button );  
due to an unexpected &.

What am I missing here?

---

<div class="post-metadata">

**Author:** ![faisalahammad](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/faisalahammad/32/13948_2.png) [@faisalahammad](https://community.gravityforms.com/u/faisalahammad)\
**Post date:** [March 28, 2023, 4:41pm UTC](https://community.gravityforms.com/t/gform-submit-button-append-javascript-example-throws-error-resolved/14811/2 "2023-03-28T16:41:48Z")

</div>

You may have encountered a minor issue with the HTML entities in your code. No worries, I’ve fixed it for you! Just replace the existing code with this one:

```auto
add_filter( 'gform_submit_button', 'add_onclick', 10, 2 );

function add_onclick( $button, $form ) {
    $dom = new DOMDocument();
    $dom->loadHTML( '<?xml encoding="utf-8" ?>' . $button );
    $input = $dom->getElementsByTagName( 'input' )->item(0);
    $onclick = $input->getAttribute( 'onclick' );
    $onclick .= " addAdditionalAction('Additional Action');"; // Here's the JS function we're calling on click.
    $input->setAttribute( 'onclick', $onclick );

    return $dom->saveHtml( $input );
}

```

Copy and paste the code above into your **functions.php** file, and you should be good to go!

---

<div class="post-metadata">

**Author:** ![alex.tocco88](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@alex.tocco88](https://community.gravityforms.com/u/alex.tocco88)\
**Post date:** [March 28, 2023, 4:48pm UTC](https://community.gravityforms.com/t/gform-submit-button-append-javascript-example-throws-error-resolved/14811/3 "2023-03-28T16:48:48Z")

</div>

Yeah that fixed my issue, thanks!

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [March 28, 2023, 7:26pm UTC](https://community.gravityforms.com/t/gform-submit-button-append-javascript-example-throws-error-resolved/14811/4 "2023-03-28T19:26:26Z")

</div>



---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [March 28, 2023, 7:27pm UTC](https://community.gravityforms.com/t/gform-submit-button-append-javascript-example-throws-error-resolved/14811/5 "2023-03-28T19:27:46Z")

</div>

The issue here was with [the documentation page](https://docs.gravityforms.com/gform_submit_button/#h-4-append-a-javascript-action-to-the-button), which has been updated. Thanks @faisalahammad for bringing that to our attention.
