# Run javascript function using button component

**URL:** <https://forums.realmacsoftware.com/t/run-javascript-function-using-button-component/53904>\
**Category:** Elements\
**Created:** [January 26, 2026, 3:27pm UTC](https://forums.realmacsoftware.com/t/run-javascript-function-using-button-component/53904 "2026-01-26T15:27:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![beretrouge](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/beretrouge/32/28746_2.png) [@beretrouge](https://forums.realmacsoftware.com/u/beretrouge)\
**Post date:** [January 26, 2026, 3:27pm UTC](https://forums.realmacsoftware.com/t/run-javascript-function-using-button-component/53904/1 "2026-01-26T15:27:57Z")

</div>

May it’s very simple but I do not understand how to call a function using the button component.  
I created a custom component and pasted this simple code:

```auto
script>

  function myFunction() {

    alert('Button clicked!');

  }

</script>

```

And I did find how to run the script with text links or button links…  
Please help me,  
Thank you in advance

---

<div class="post-metadata">

**Author:** ![Tofty](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@Tofty](https://forums.realmacsoftware.com/u/Tofty)\
**Post date:** [January 27, 2026, 4:21am UTC](https://forums.realmacsoftware.com/t/run-javascript-function-using-button-component/53904/3 "2026-01-27T04:21:36Z")

</div>

Thanks for sharing, Francis. For dummies (e.g. me), was the addition of the # in the URL box the thing that made that work?

And where did you put the code for the actual function being called?

---

<div class="post-metadata">

**Author:** ![beretrouge](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/beretrouge/32/28746_2.png) [@beretrouge](https://forums.realmacsoftware.com/u/beretrouge)\
**Post date:** [January 27, 2026, 10:32am UTC](https://forums.realmacsoftware.com/t/run-javascript-function-using-button-component/53904/4 "2026-01-27T10:32:34Z")

</div>

Yes, the addition of the # in the URL box do the trick

About the function :

[![](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/f/8/f8cb40a4276952adad0c844f60facab06197122c.jpeg "Adding HTML Snippets in Elements") ](https://www.youtube.com/watch?v=rHDCpYrg-j4)

---

<div class="post-metadata">

**Author:** ![Tofty](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@Tofty](https://forums.realmacsoftware.com/u/Tofty)\
**Post date:** [January 28, 2026, 8:41am UTC](https://forums.realmacsoftware.com/t/run-javascript-function-using-button-component/53904/5 "2026-01-28T08:41:08Z")

</div>

Thanks for that. I’ve been using the HTML snippets for creating things like image maps, but I was wondering if the function you were calling from the button was something you had added to the site template code as a global function. Your post makes me think that something I have been trying to get work (and failing) with a pointer events attribute for SVG’s could be applied as an HTML snippet

---

<div class="post-metadata">

**Author:** ![beretrouge](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/beretrouge/32/28746_2.png) [@beretrouge](https://forums.realmacsoftware.com/u/beretrouge)\
**Post date:** [February 6, 2026, 3:56pm UTC](https://forums.realmacsoftware.com/t/run-javascript-function-using-button-component/53904/6 "2026-02-06T15:56:33Z")

</div>

![onclick](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/b/a/ba0bd366912c4f53e73894a1f2abf5886ac85c19.jpeg)
