3

I'd like to create a form where I have checkboxes, and when clicked, they open separate textareas for the user to enter more information in.

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

1 Answer 1

3

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

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

Be careful, I have not tested the code above! But should be enough to get you started.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that should be enough to get me started.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.