Richard
Richard

Reputation: 23

How to re-enable submit for form after it has been prevented

OK this question was asked badly originally. Here is more information and a good chunk of my code. The idea behind this code is an aspx form that has the user input information and then uses a submit button to submit the code, using C#, to a mySQL server. When they forget to enter a salesman a dialog box opens asking them again to input a salesman.

Here is the code for the dialog box.

<div id="dialog" title="Dialog Title"><asp:label id="lblSalesman" onChange="GetSalesman()" Runat="server" /></div>   //THE ASP:LABEL REFERS TO A DROP DOWN LIST THAT WAS CREATED AND POPULATED BY c#.
   <script type="text/javascript" language="javascript">
       function stopSubmit() {
        $('form').bind('submit', function (event) {
        event.preventDefault();
       });
                             }

      $("#dialog").dialog({
        autoOpen: false,
        modal: true,
        buttons: {
        "Save": function () {

      $('#btnSubmit').click('btnSubmit');   //THIS IS SUPPOSED TO CLICK A BUTTON ON THE ORIGINAL ASPX FORM THAT WILL TRIGGER C# TO SUBMIT THE FORM TO A MYSQL SERVER
      $(this).dialog("close");
         }
        }
      });

      $("#opener").click(function () {
          stopSubmit();                      
          $("#dialog").dialog("open");
      });

   </script>

The all caps are comments for you guys.

This dialog box is triggered by a validation statement. If the validation fails the dialog box runs. I put this,

$('form').bind('submit', function (event) {
        event.preventDefault();

in a function so in case this code doesn't run, then my submit button on my original form still works if the validation comes up true. This effectively stops the dialog box from reloading the page after the dialog box is triggered. The problem is that the SAVE button in the dialog box can't run the $'(#btnSubmit').click('btnSubmit'); because the event.preventDefault prevents the submit built into the button to not work. Is there any way to undo the event.preventDefault() or another way to submit the form?

Upvotes: 1

Views: 2150

Answers (3)

Richard
Richard

Reputation: 23

Sorry for all the confusion with this question. It has exactly been a peach for me. I found the answer though. I used the code below to allow submit to work again.

$('form').unbind('submit');

This just unbinds the

event.preventDefault();

from the submit event.

Upvotes: 0

Rickyrock
Rickyrock

Reputation: 328

<form onsubmit="return false"></form> It will work

$("#btnSubmit").trigger("click");

Upvotes: 1

Chirag Vidani
Chirag Vidani

Reputation: 2577

This code will stop script to go back to server. Return false stops execution of script on client side

$('form').on('submit', function(event){
return false;
});

Upvotes: 0

Related Questions