#Toggle switch

5 messages · Page 1 of 1 (latest)

trail crow
#

Did you try registering an event in javascript?

fast harbor
#

I also think that one approach would be to register an event in JS.

knotty tiger
storm schooner
#

What HAVE you tried?

knotty tiger
#
<script>
        $(document).ready(function () {
            $('#myToggle').on('change', function () {
                const isChecked = $(this).is(':checked');
                const status = isChecked ? 'on' : 'off';
                const botid = $('tr').attr('data-pk');

                $.ajax({
                    url: `{% url "status-update" ${botid} %}`,  // Sending checkbox state as a GET parameter
                    type: 'GET',
                    success: function (response) {
                        console.log('Success:', response.message);
                    },
                    error: function (xhr, status, error) {
                        console.error('Error:', error);
                    }
                });
            });
        });```