As the title says really. How can i get the values of the checkboxes which are checked from a dynamically created group of check boxes.
bit stuck on this one…… I have this code:
any help would be great.
[CODE]
<html>
<head>
<script language=”Javascript”>
var array = new Array();
array.push(“foo”);
array.push(“bar”);
array.push(“test”);
array.push(“one”);
function createCheckBoxes()
{
document.getElementById( ‘append’ ).innerHTML = “”;
for(var i=0; i<array.length; i++) {
var divTag = document.createElement(“div”);
divTag.className =”filterCheckBoxes”;
divTag.id = “filterCheckBoxes”;
var cb = document.createElement( “input” );
cb.type = “checkbox”;
cb.id = “checkBoxes”+i;
cb.checked = true;
cb.value = array[i];
document.getElementById(“append”).appendChild(divTag);
divTag.appendChild(cb);
divTag.appendChild(document.createTextNode(array[i]));
}
}
function alertChecked()
{
for (var i=0;i<array.length;i++) {
if(document.getElementById(“filterCheckBoxes”).checked == true){
alert(document.getElementById(“filterCheckBoxes”).firstChild);
}
}
}
</script>
</head>
<body>
<p>click the button below</p>
<div id=”append” name=”append”></div>
<input type=”button” value=”createCheckBoxes” onclick=”javascript:createCheckBoxes()” />
<input type=”button” value=”test” onclick=”javascript:alertChecked()” />
</body>
</html>