mercredi 23 octobre 2019

uncheck and check all checkboxes with a button in flask

I have a flask app that has a bunch of checkboxes, some of the pre-checked. I would like to have a button that checks/unchecks all the checkboxes. I realized that I should do it with a javascript function, so I created a file script.js in the static folder and put these functions in it:

$("#uncheck-all").click(function(){
    $("input[type='checkbox']").prop('checked',false);
});


$("#uncheck-all").click(function(){
    $("input[type='checkbox']").prop('checked',true);
})

Then I addressed the file in the template:

<script type="text/javascript" src=""></script>

and added the buttons on the page:

<input type="button" id="uncheck-all" value="UncheckAll"/>
<input type="button" id="check-all" value="CheckAll"/><br>

But unfortunately, none of them work. I would appreciate it if anyone helps me with it.




Aucun commentaire:

Enregistrer un commentaire