-1

I got this code here:

It works fine as far as disabling and replacing the Submit button goes, but it will not submit the form. My form uses the 'get' method and submits data to another page.

 <script type="text/JavaScript">
    $('.button').click(function() {
        $('.button').remove();
        $('.holder').append("DONT DOUBLE CLICK ANYTHING IN A BROWSER");
        $('.form').submit();
    });
    </script> 

I have tried most things, including changing .form to the id of my form, still no joy, any ideas would be helpful.

HTML code

<form action="liftingConfirm.asp" method="get" id="frmArchiveConfirm">
<input name="con_id" type="hidden" id="con_id" value="<%=request.querystring("con_id")%>" />
<input name="sub_id" type="hidden" id="sub_id" value="1" />
<input name="liftingDate" type="hidden" id="liftingDate" value="<%=Session("currentUSDate")%>" />
<div class="holder"><input name="btnConfirm" type="submit" class="button" id="btnConfirm" value="Start New Lifting Gear Examination"  /></div>
Community
  • 1
  • 1
Duncan Cook
  • 85
  • 2
  • 10

2 Answers2

2

You're using the wrong selector, the .form is looking for a <form> with a class of form. Furthermore you should be using the on() syntax:

$('form').on('click', '.button', function() {
    $('.holder').append("DONT DOUBLE CLICK ANYTHING IN A BROWSER");
    $('#frmArchiveConfirm').submit();
    $('.button').remove();
});
Tom Walters
  • 15,366
  • 7
  • 57
  • 74
  • so i need to tag the form with class="form" aswell? – Duncan Cook Mar 12 '13 at 08:27
  • No, the selector `form` selects all `
    ` elements, if you want to select only the form in your question you could use the ID selector `#frmArchiveConfirm`. [This article](http://sunali.com/2010/02/03/introduction-to-jquery-and-jquery-selectors/) is a good introduction to selectors and jQuery in general.
    – Tom Walters Mar 12 '13 at 08:30
  • Thanks Tom, the form seems to do something (the egg timer now appears when i hit submit) but it only replaces the submit button, form tries to do something, then button re-appears) I have checked the dbase the form isn't submitting the data. please note this submit path worked fine until I added code to try and stop double clicking. – Duncan Cook Mar 12 '13 at 08:35
  • Depending on what browser you're using, you should use the Inspector to trace calls made to the server (try right-clicking and selecting _Inspect Element_) – Tom Walters Mar 12 '13 at 08:36
  • I have traced it, it's actually doing nothing, just reloading the same page. – Duncan Cook Mar 12 '13 at 08:42
  • [Let's continue this in chat](http://chat.stackoverflow.com/rooms/26008/jquery-submit-question) – Tom Walters Mar 12 '13 at 08:46
0

For your jQuery code to work you should include the frmArchiveConfirm to your jQuery code as below.

Replace $('.form').submit(); with $('#frmArchiveConfirm').submit();

else if you only having one form in the page just use $('form').submit();

When you come across bug like this don't forget to make use of the firebug or the browser development tools. You can easily figure out the bug and what's wrong in your code.

Techie
  • 44,706
  • 42
  • 157
  • 243