Is there anything special I should be doing in ASP.NET when I want to submit a form when a checkbox is clicked. This is some sample HTML I am using...
<form method="post" action="#">
<input id="hi" class="hidden-field" type="checkbox" value="true" onclick="this.form.submit();" name="hi">hi</input>
</form>
I tested this in JSFiddle and when you click the checkbox, it naturally posts the form. Somehow I can't get this working inside a MVC PartialView.
Use Javascript/jQuery:
$(document).on("click", "#hi", function(){
if ($(this).is(':checked')) {
$('form').submit();
}
});
All you need is to bind a function on the click event, and in that function, call submit() manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With