开发者

JavaScript function calls within Django form fields

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜