# Run JavaScript from an HTML Button Onclick Event

> This is a solution to add a button anywhere on the page that would open a popup.

Source: https://tadabase.com/docs/snippets/run-javascript-from-an-html-button-onclick-event  
Status: Not yet re-checked. Moved from our previous help site and not yet re-checked against the current product. Last edited Sep 20, 2024.

![Screenshot for “Run JavaScript from an HTML Button Onclick Event”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-10/scaled-1680-/2022-10-01-00-11-45.png)

This is a solution to add a button anywhere on the page that would open a popup.

**Step 1**

**Add an HTML component to your page, open its settings, and add the following code within the source code <> tab.**

```
<div class="feedback" style="text-align: right;"><button id="feedback-btn" class="btn"> <img src="exclamation-mark.png" width="25px" height="25px" /> </button></div>
```

![Screenshot for “Run JavaScript from an HTML Button Onclick Event”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-10/scaled-1680-/image-1664596515566.png)

**Step 2**

**Save the HTML component and hover over the info icon to get the component ID.**

![Screenshot for “Run JavaScript from an HTML Button Onclick Event”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-10/scaled-1680-/image-1664596605024.png)

**Step 3**

**Add the following code to the JavaScript tab of your page.**

```
TB.render('component_ID', function(data) {
    $('#feedback-btn').on('click', function() {
        var url = "http://www.example.com";
        var width = 960;
        var height = 1040;
        var left = screen.width - 400;
        var top = 5;
        var params = "width=" + width + ", height=" + height;
        params += ", top=" + top + ", left=" + left;
        params += ", directories=no";
        params += ", location=no";
        params += ", menubar=no";
        params += ", resizable=no";
        params += ", scrollbars=no";
        params += ", status=no";
        params += ", toolbar=no";
        newwin = window.open(url, "customWindow", params);
        if (window.focus) {
            newwin.focus();
        }
        return false;
    })
});
```

> **Note:** Remember to edit the code to your component ID and the URL you wish to display.

![Screenshot for “Run JavaScript from an HTML Button Onclick Event”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-10/scaled-1680-/image-1664597342297.png)

**Original Community Post:**

[Run JavaScript from an HTML button onclick event - Community Discussions / Tips and Tricks - Tadabase Community](https://community.tadabase.io/t/run-javascript-from-an-html-button-onclick-event/1896)
