Why am I submitting a form twice? jQuery submit () with switch

I am using jQuery to submit a form in an MVC application. I have a breakpoint inside the controller, and I see that it hits twice. What am I doing wrong?

Here is my jQuery

 (function ($) {

    $(document).ready(function () {

        $(':radio').change(function () {

            $('#frmMDR').submit();
        });

    });
})(jQuery);

and here is the html form

<form action="/Module/ModuleIndex" id="frmMDR" method="get">
  <input id="rdoMaintenance" name="module" type="radio" value="Maintenance" /><label for="rdoMaintenance">M</label>
   <input id="rdoDiagnostics" name="module" type="radio" value="Diagnostics" /><label for="rdoDiagnostics">D</label>
   <input id="rdoRepair" name="module" type="radio" value="Repair" /><label for="rdoRepair">R</label>
 <input id="hdnVehicle" name="hdnVehicle" type="hidden" value="" />
</form>

I assume that I should not use the change event. If anyone knows how to fix the problem, I would like to hear any ideas. Thanks so much for any advice.

Cheers,
~ ck in San Diego

+3
source share
2 answers

, . , , , :

, . , , .

<input class="radio" id="rdoMaintenance" name="module" type="radio" value="Maintenance" /><label for="rdoMaintenance">M</label>
<input class="radio" id="rdoDiagnostics" name="module" type="radio" value="Diagnostics" /><label for="rdoDiagnostics">D</label>
<input class="radio" id="rdoRepair" name="module" type="radio" value="Repair" /><label for="rdoRepair">R</label>

jQuery :

$('.radio').click(function () {
    $('#frmMDR').submit();
});
+6

, , . , - , , .

JQuery.

+3

Source: https://habr.com/ru/post/1780480/


All Articles