{in" /> {in" /> {in"/>

Auto click a button Javascript

41 Views Asked by At

I have a module for prestashop that opens a tab when it is selected. Here is the code:

<script src="https://examplewebsite/pluginsdk.js"></script>
{include file='./_partials/test.tpl'}
{if $boxes|count}
    <table class="resume table table-bordered">
        <tbody>
            <tr>
                <td>{l s='Select box' mod='boxselection'}</td>
                <td> 
                    <button type="button" name="boxselection_id" id="showBoxLocation" data-country='{$hostCountry}' class="button-exclusive btn btn-default">
                        {l s='Show Box location' mod='boxselection'}
                    </button>
                </td>
                <td>
                    <input type="hidden" id="box_name" name="box_name" value="">
                    <input type="hidden" id="box_address" name="box_address" value="">
                    <span style="padding-bottom: 10px;font-size: 13px; font-weight: bold; line-height: 22px;width:100%;display:block" id="showBoxDetails"></span>
                </td>
            </tr>
        </tbody>
    </table>
{/if}

I tried to use this code:

<script>
      window.onload = function () {
        var button = document.getElementById('showBoxLocation');
        button.click();
      }
</script>

But it only works half. If I select the option to open the tab with the Button it doesn't work. No auto-click. But if I refresh the page the auto-click works.

What am I doing wrong?

0

There are 0 best solutions below