-1

When this code running my form is submit and not end submit.

How can stop submit when count is 0?

function btnCheck_Click() {
  var count = parseInt(61);
  myCounter = setInterval(function () {
  if (count > 0)
    count--;
    elem.html( count );
  }, 1000);
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Masoud Sadeg
  • 531
  • 2
  • 6
  • 13

1 Answers1

0

You can most easily cancel a form submit from within the submit handler, so with something like this:

<form onsubmit="return validateClickCount()" />

Now if you have a function validateClickCount, the submit action will be canceled when it returns false.

function validateClickCount() {
  return false;
}

With this in place, you just need to change your btnCheck_Click/interval-callback to decrease a global counter and then check that counter in the validateClickCount.

var count = 61;
function btnCheck_Click() {
  myCounter = setInterval(function () {
    if (count > 0)
      count--;
      elem.html( count );
  }, 1000);
}

function validateClickCount() {
  return count > 0;
}

If you're looking for more information, I suggest looking at this question and the answers too: How do I cancel form submission in submit button onclick event?

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807