I've got a few boxes containing image, text and checkbox:
<label name="skill" id="testbox" class="box tooltip" onclick="toggleCheckbox('test');" style="background-image:url('red.png')">
<span><img class="callout" src="callout.png"><script>document.write (test);</script></span>
<div class="margin">
<img src="">
test<input name="choice" value="1" id="test" type="checkbox" onchange="onCheckboxChanged(); checkTotal();" disabled>
</div>
I try to take the id (testbox) when I click anywhere in the label and use it in this function:
var onCheckboxChanged = function(checkbox){
var test = document.getElementById('test');
var testbox = document.getElementById('testbox');
var structure = document.getElementById('structure');
var structurebox = document.getElementById('structurebox');
if(structure.checked){
test.disabled = false;
structurebox.style.backgroundImage='url(green.png)';
}
else{
test.disabled = true;
structurebox.style.backgroundImage='url(grey.png)';
}
if(test.disabled){
testbox.style.backgroundImage='url(red.png)';
}
else {
if(test.checked){
testbox.style.backgroundImage='url(green.png)';
}
else{
testbox.style.backgroundImage='url(grey.png)';
}
}
};
I can just copy/paste the code and change id's but I've got over 70 boxes and there will be more. I tried:
document.getElementsByName("skill")[0].getAttribute('id')
but it probably takes all id's from boxes with name "skill". I guess I should use something similar to this and it works but I don't know how to connect it to my code so I can use clicked id from this function in my function (as var would be the best).