Asp.net mvc: checkbox onchange not working

I have a page with a set of checkboxes that I want to run the javascript function when a change occurs (I did something very similar with a drop down list - and it worked)

However, using the checkbox I have three problems:

  • my onChange event only fires “sometimes” (you need to change the focus between the various checkbox elements

  • when it starts, the result of the previous flag is returned (and not just the one that was clicked)

  • jQuery always returns true

Create Flags

<%= Html.CheckBox("sl-" + row.Id, value, new { onChange = "SuitabilityChecked("+row.Id+", "+key+")"})%>

Javascript

function SuitabilityChecked(providerId, parentRecordId) {
            var params = {};
            params.providerId = providerId;
            params.parentRecordId = parentRecordId;

            var value = $("#sl-" + providerId).val();               

            params.value = value;            
            $.getJSON("SuitabilityChecked", params, null);
        };
+3
source share
2 answers

onchange . onclick, .

, - jQuery Live (, ):

$(':checkbox').live('click', function() { $(this).change(); });
+3

:

  • A
  • B
  • A ""

, Checkbox B Checkbox A. Tab B , , onChange .

0

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


All Articles