Checkbox onchange function

asp.net-mvc, dom-events, javascript

Solution

Browsers are funny about radio buttons and check boxes and can delay the onchange until focus change. Try adding an onclick event to blur or call the change event directly.

Maybe something like this using jQuery Live (untested, off the top of my head):

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

Problem

I have a page with a set of checkbox's, that I want to run a Javascript function on when there is a change (I have done something very similar with dropdown's - and that worked) However with the checkbox's I have three problems: my `onChange` event only runs "sometimes" (you have to change the focus between the different checkbox controls when it does run it is returning the result of the previous checkbox (not the one just clicked on) the jQuery always return the value true Checkbox creation ``` <%= 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); }; ```

Original source