Frank Fan Frank Fan - 1 year ago 43
Javascript Question

change the number of checkboxes in HTML using javascript

I would have a group of checkboxes in the HTML page but the number of checkboxed depends on a uploaded file.

For example, suppose that the uploaded file is a data set which contains five columns. Thus automatically there should be five checkboxes on the website and user can select columns by checking the corresponding boxed.

I am thinking about how to use javascript (or jQuery) to solve this problem.


Read the files array using $('input[name^="name_of_file_input"]')[0].files, and then count the number of files, create the html inside a loop (whose max value to the files count) for the check boxes and render into your form. Hope it helps !

for example

var checkboxes = "";
for(var i = 0;i<=5;i++){
   checkboxes += "<input type='checkbox' name=''/>";