E
E
Elena Fire2021-07-14 23:30:37
JavaScript
Elena Fire, 2021-07-14 23:30:37

How to make clicking on the a tag when submitting the form by pressing enter?

There is a form. The submit button has an onclick event and a link that reloads the page. It is necessary that after filling out the form and pressing Enter - the submit event - there is a click on the link in the Submit button to reload the page.
I write like this:

function ClearCart(element) {
    var href = element.href;  
    if (href)               
      $.get(href, function(data){
        $("cart").html('');
        BX.onCustomEvent('OnBasketChange');
     location.reload(true);
    });     

    return false;
  }

 document.getElementById('ocf-submit').on("submit", function(e) {
    e.preventDefault();
    document.getElementById('btn-ocf-submit').onclick = ClearCart();
  });

bnt-ocf-submit is the id of the tag a
ocf-submit is the id of the form tag form
ClearCart - this function updates the cart data in the header

But my script is not working. How to write a script correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2021-07-15
@BormotunJedy

spoiler
document.getElementById('ocf-submit').on("submit", function(e) {
    e.preventDefault();
    ClearCart(document.getElementById('btn-ocf-submit'));
});

UPD
document.getElementById('ocf-submit').addEventListener("submit", function(e) {
    e.preventDefault();
    ClearCart(document.getElementById('btn-ocf-submit'));
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question