Home > Back-end >  Submit Form afer change Checkbox
Submit Form afer change Checkbox

Time:01-04

I want to submit a Form after a checkbox is changed in a twig file like:

{{start_form(einrichtungUsersForm.getEinrichtungUserType())}}
{{ form_widget(einrichtungUsersForm.getEinrichtungUserType().active )}}
{{ende_form(einrichtungUsersForm.getEinrichtungUserType())}}

Is that possible?

CodePudding user response:

yes you can do it with jquery like this :

$('body').on('change', '#checkboxId', function() {
    $(this).closest('form').submit();
});

If you don't use jquery, this is the solution with javascript :

let checkbox = document.getElementById('checkboxId');
checkbox.addEventListener('change' => () {
    this.closest('form').submit();
});
  •  Tags:  
  • Related