IE submit the forms twice

9.2k Views Asked by At

I have this problem in IE, sometimes my form is submitting twice. I know the issue of clicking the button twice and that is not the problem. But on my case I only click it once. I checked my records in the database and there are two records.

<input type="button" value="Approve" name="btn_approve" id="btn_approve">
<input type="button" value="Reject"  name="btn_reject" id="btn_reject">

<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> 
<script type="text/javascript" src="js/jquery-ui-1.8.20.custom.min.js"></script> 
<script>
$(document).ready(function () {
    $("#btn_approve").click(function () {
        // some validation before submitting the form

        $("#my_form").submit();
    });
});
</script>
3

There are 3 best solutions below

2
On

Prevent the default behaviour of the button:

<input type="button" value="Approve" name="btn_approve" id="btn_approve">
<input type="button" value="Reject"  name="btn_reject" id="btn_reject">

<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> 
<script type="text/javascript" src="js/jquery-ui-1.8.20.custom.min.js"></script> 
<script>
$(document).ready(function () {
    $("#btn_approve").click(function (e) {
        e.preventDefault();
        // some validation before submitting the form

        $("#my_form").submit();
    });
});
</script>
4
On

Assuming that #btn_approve is actually a submit button inside of #my_form, you are triggering the form submission via .submit and the browser is also submitting it normally. Change to:

$("#btn_approve").on('click', function (e) {
   $("#my_form").trigger('submit');

   e.preventDefault();
});
0
On

I have the same issue. I time-stamp my records as I save them to the database. So if a record is submitted for a specific unique user, within 2 seconds from each other, I just ignore the duplicates. This way I don't need to check for browser types and compatibility on the client side, just handle the issue on the server side, respectively of the browser.

        '' Count the number of submissions, for the user, within the 2 seconds.
        objRS.open "select count(*) as C FROM [ADS].[dbo].[VIP_USERS] where userid = '" & Trim(Request("USERID")) & "' and datediff(ss, created, GETDATE()) <= 2", Application("sConn")