JS加载页面时强制单击输入按钮

I have an input button which needs to be clicked automatically when the page loads. I have the following input button code:

<form enctype="multipart/form-data" name="cart" action="cart.php#order_statistics" method="POST">               
   <table id="order_statistics">
      echo '<td><button type="submit" id="refreshCart" style="border: none; background: none; cursor: pointer;" name="clicked" value="Update Order"><img src="images/refresh.png" alt="Refresh Image"/></button></td>';
   </table>
</form>

I have tried several other ways of doing this but to no avail. When I tried other ways of doing this, the script I used would press the button automatically but the page would keep refreshing and would be on a constant looping refresh.

I don't know if it may be because of the action in the form tag?

Any help would be appreciated.

My page (cart.php) code can be found here

change your form to

<form enctype="multipart/form-data" name="cart" action="cart.php#order_statistics" method="POST">               
   <table id="order_statistics">
      echo '<td><button id="refreshCart" style="border: none; background: none; cursor: pointer;" name="clicked" value="Update Order"><img src="images/refresh.png" alt="Refresh Image"/></button></td>';
      echo '<td><button type="submit" style="border: none; background: none; cursor: pointer;" name="clicked" value="Place order Order"><img src="images/Place order.png" alt="Place order Image"/></button></td>';
   </table>
</form>

add this command to your script.

$("#refreshCart").trigger("click");

check out trigger() function.

With jQuery:

$(window).load(function() {
    $('#refreshCart').click();
});


Or native JavaScript:

window.onload = function() {
  document.getElementById('refreshCart').click();
};


To avoid the infinite loop did you comment, you need to change the submit by an AJAX request:

$(window).load(function() {
    $.ajax({
        url: "/your_form.php",
        type: "post",
        data: your_data
    });
});

I believe what you want to do is submit your form by clicking the button, So I would suggest you programmatically submit the form with this.

Approach1 :

document.cart.submit();

Approach2: Give a Id to your form and then

document.getElementById('giveSomeIdToForm').submit();

Also, to programmatically click the button,

document.getElementById('refreshCart').click();