lundi 30 mars 2020

How to fill checkbox with data in a config file using JavaScript?

I would like to be able to fill a list of checkbox with datas from a config file.

In fact, if my checkbox is made to choose a Sport, in my config file I have something like this in JSON :

sports: ["Tennis", "Rugby", "Soccer"]

I would like my checkbox to be adaptative, means that the number of inputs is mapped on the length of the table in the JSON file.

Thank you very much for your help !

Edit :

Here is my HTML code

<div class="form-check">
    <label for="editSports">Pick your sport(s)</label>
    <input type="checkbox" class="form-control" id="editSports" name ="editSports">
    </input>
</div>

And I am wondering how to fill it with Javascript, I guess I'll have to do something like this :

ddn = $("#editSharedFolders");
config.sports.forEach(sport=> {
        ddn.append($('<checkbox>', {value: sport, text: sport})); //This line is the problem I guess
});



Aucun commentaire:

Enregistrer un commentaire