Reputation: 53
I created a list of roles using checkbox and trying to let the checkbox directly perform an action when the checkbox was checked without clicking a button. Anyone could assist me in this?
Thanks!!
Upvotes: 0
Views: 951
Reputation: 1039418
You could use AJAX. For example with jQuery you could subscribe to the .change
event of the checkbox and perform some action:
$(function() {
$(':checkbox').change(function() {
// this will be trigerred when the checkbox is checked or unchecked
// here you could perform the desired action, like for example auto submit
// the containing form. Like this:
$(this).closest('form').submit();
// or send an AJAX request or whatever you need
});
});
Upvotes: 1
Reputation: 107
You can use the onCheckedChanged property of the checkbox.
OnCheckedChanged : The name of the function to be executed when the Checked property has changed.
And write the function in the script section of the page. so whenever your checkbox is checked or unchecked it will call the specified method where you can write your logic.
for reference you can visit this link
Upvotes: 1