vendredi 17 avril 2015

Call function when checkbox is clicked in JavaScript?

I've created some checkboxes dynamically using JavaScript (below), any ideas on how to call a function when a checkbox is clicked?



var eng_types = table[3].slice(3);
for(var i in eng_types) {
var name = eng_types[i];

// create the necessary elements
var label= document.createElement("label");
var description = document.createTextNode(name);
var checkbox = document.createElement("input");

checkbox.type = "checkbox"; // make the element a checkbox
checkbox.name = i; // give it a name we can check
checkbox.value = name; // make its value "pair"

label.appendChild(checkbox); // add the box to the element
label.appendChild(description);// add the description to the element

// add the label element to your div
document.getElementById('eng_options').appendChild(label);

}


Any pointers on how to make each checkbox appear on a new line would also be appreciated.


Thanks in advance!





Aucun commentaire:

Enregistrer un commentaire