I'm having trouble referencing a checkbox element from an array of element ids. Why can I reference it using a literal and string var as the parameter of getElementById, but not by using an element of an array?
<html>
<body>
<ul id="zip_wrapper">
<li><label><input type="checkbox" id="72002" value="72002" name="zip_codes[]" checked="checked">72002</label></li>
<li><label><input type="checkbox" id="72034" value="72034" name="zip_codes[]" checked="checked">72034</label></li>
</ul>
<script>
var zips = "";
var tester = "72034";
zips = document.getElementById("zip_wrapper").innerText.split(" ");
//zips = Array.prototype.slice.call(zips); //a la http://stackoverflow.com/questions/4287681/extremely-annoying-javascript-array-object-error
document.write("zips array, tokenized by split(\" \"): " + zips + "<br />");
document.write("document.getElementById(\"72034\").checked: " + document.getElementById("72034").checked + "<br />");
document.write("document.getElementById(tester).checked: " + document.getElementById(tester).checked + "<br />");
document.write("document.getElementById(zips[1]).checked: " + document.getElementById(zips[1]).checked + "<br />");
</script>
</body>
</html>
You can see the page in action here: https://dl.dropbox.com/u/1634015/website/checked.html
zips[1]? -->console.log(zips)orconsole.log(zips.length);)undefinedfor the "innerText" of the<ul>element ...