Calling JavaScript functions in Django form fields

I would like to create a form where I have checkboxes, and when clicked, they open separate text fields so that the user can enter additional information.

If I want to use dynamically created fields of a Django form, there is a way that I can put a function call for each checkbox.

+3
source share
1 answer

You can dynamically add event handlers using JavaScript. You can add a script that, as soon as the page is loaded, finds all the checkboxes you want, and add handlers there. In jQuery you can write something like this:

$(document).ready(function() {
    $(".my_form input[type=checkbox]").change(function() {
          //Some code here
    });
});

, ! , .

+3

Source: https://habr.com/ru/post/1774929/


All Articles