JQuery disable submit button on click to prevent multiple form submit

We will learn how to disable a button on click in jquery in this short post to stop multiple form submissions. Using jquery, we can prevent the submission of duplicate forms. In jquery, we can quickly block a button’s on-click event to prevent double-form submission.

When working with PHP or another framework, such as Laravel , CodeIgniter, you might use a form with just one submit button. We have a big, complicated form that might take some time to submit, so users can click repeatedly without the form really submitting.

Therefore, we must stop numerous form submissions, just as we must stop double-clicking the submit button. so how we can prevent this? we can do it using jquery. when you click on submit button.

$(document).ready(function() {
  $('form').submit(function() {
    // Disable the submit button
    $(this).find(':submit').prop('disabled', true);
  });
});

Here is a full example, you can see.

<!DOCTYPE html>
<html>
<head>
    <title>jQuery disable submit button on click to prevent multiple form submits - Cotocus.com</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
   
<form id="myForm">
    <input type="text" name="name" placeholder="Name...">
    <input type="text" name="email" placeholder="Email...">
   
    <button type="submit" id="myButton">Submit</button>
</form>
   
<script type="text/javascript">
   
$('#myForm').submit(function(){
    $("#myButton", this)
      .html("Please Wait...")
      .attr('disabled', 'disabled');
    return true;
});
   
</script>
   
</body>
</html>

I hope it can help you!!!

Related Posts

Ask a Doctor Online: A Simple Guide to Virtual Healthcare

In our fast-paced world, the traditional trip to a doctor’s office isn’t always the most practical first step when health concerns arise. Whether you are dealing with…

Read More

Best Free Programming Ebooks to Learn Software Development

Learning modern technology can feel overwhelming when tutorials are scattered across dozens of websites. Many software developers, engineering students, and IT professionals struggle to find comprehensive study…

Read More

FinOps Training: Understanding Cost Visibility and Optimization

Introduction Moving workloads to the cloud can simplify infrastructure management, but it can also introduce a new financial challenge. Teams can provision resources whenever they need them,…

Read More

The Architecture of Intelligent DataOps: From Ingestion to Automation

Introduction Modern organizations run on distributed data ecosystems. On any given day, an enterprise environment ingests, transforms, and serves petabytes of records sourced from transactional databases, external…

Read More

Transforming Data Reliability: How DataOps Platforms Drive Proactive Monitoring

Introduction Traditional monitoring focuses almost entirely on infrastructure availability and binary job execution states—whether a server is up or whether a task completed. However, modern distributed environments…

Read More

Navigating Pipeline Risks with Expert DevSecOps Consulting Services

Software delivery moves faster today than at any point in technological history. High-performing engineering organizations push code changes to production multiple times a day using automated deployment…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x