IE submit the forms twice
Asked Answered
D

3

5

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>
Darendaresay answered 17/1, 2013 at 7:5 Comment(0)
A
11

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>
Apgar answered 17/1, 2013 at 8:9 Comment(2)
Yes, this is the correct one. e.preventDefault(); should be executed first before submit(). Thanks!Darendaresay
I also had this just now with a self-created css button (a couple of div's put together). I don't know why, but this solved it for me as well.Selfabnegation
D
4

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();
});
Dissonancy answered 17/1, 2013 at 7:9 Comment(4)
On the code shown on the question, btn_approve is of type button.Repeat
@MartínCanaval 1. How do you know that 2. Why does it matter?Dissonancy
<input type="button" value="Approve" name="btn_approve" id="btn_approve"> this is the first line on the code he posted. I'm just mentioning it just in case.Repeat
@MartínCanaval oh I see I thought you meant it was a button element. I think the problem is that type="button" submits forms in IE but not the other browsers. Just a guess.Dissonancy
C
0

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")
Carlo answered 2/10, 2013 at 14:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.