setting created checkbox as checked not working
thanks for helping... I'm creating a series of html elements in
javascript, including checkboxes. I want to go ahead and mark one of the
checkboxes by default. I cannot get the 'checked' property to exist using
either pure javascript (checkbox.checked = true;) or jquery library (see
below). See my example, thank you:
function createToolbarElements(){
//------topbar-------------
var topbar = document.getElementById("topbar");
topbar.innerHTML = "ZONE: ";
//zone set
ART.regions.unshift("All");
ART.regions.push("osj");
var numRegions = ART.regions.length;
var region;
for(i=0; i<numRegions; i+=1){
region = ART.regions[i];
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.name = region;
checkbox.value = region;
checkbox.id = "zone"+region;
if(region === "All"){
$("zoneAll").prop("checked", true);
}
topbar.appendChild(checkbox);
var label = document.createElement('label')
label.htmlFor = region;
label.appendChild(document.createTextNode(region));
topbar.appendChild(label);
}
}
No comments:
Post a Comment