(This is not the answer you're looking for.)
Let me propose a simplification, although there are a couple of things to keep in mind:
- The function could use a better name since it does more than just toggle checkboxes.
- You might want to consider using a JavaScript framework that streamlines DOM manipulation.
function check() {
setChecks(false);
}
function uncheck() {
setChecks(true);
}
function setChecks(checked) {
var leftSide = document.getElementById('table_container_left');
var inputs = leftSide.getElementsByTagName('input');
var textValue = checked ? "1" : "0";
var x;
for (x = 0; x < inputs.length; x++) {
if (inputs[x].type == 'text') {
inputs[x].value = textValue;
} else {
inputs[x].checked = checked;
}
}
}
You may also want to think about initializing arrays immediately and using objects. Additionally, the object containing the computers should be named appropriately as computers
. It's not just one computer, it's multiple computers; plural.
var computers = [
{ id: "10001", name: "Nvidia Geforce GTX 690", price: 1200 },
{ id: "10002", name: "Raedon HD 7950", price: 450 },
// ...
];