How not to send many records by clicking often on the button

Asked

Viewed 50 times

2

I have a button, where I’ve seen several topics and one of the solutions it disables, but does not send the data.

Button code:

<button onclick="this.disabled = true; this.form.submit(); return true;" name="enviar">Enviar</button>

  • Friend, I think a <input type="Submit" value="Send" /> would solve your problem, replace your button with the input above :D

2 answers

0

Behold this functional example using jQuery, taken from another question from ONLY in English.

HTML:

<form class="form-horizontal">
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <div class="checkbox">
        <label>
          <input type="checkbox"> Remember me
        </label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default">Sign in</button>
    </div>
  </div>
</form>

Javascript:

$('form').submit(function(){
    $(this).find('button[type=submit]').prop('disabled', true);
    return false;
});

0

If the problem is related to ajax requests, another way is the method one.

Behold:

$('form').one('submit', function()
{
   // Meu ajax é chamado aqui 
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.