I have this script where, when you click the checkbox, the text next to it is highlighted.
I need it to do that for a whole list of checkboxes. (When you click checkbox 1, text 1 highlights, when you click checkbox 2, text 2 highlights, etc.) But I can’t get the syntax right. Here is the code:
[code]
<script type=”text/javascript”>
function highlight3(myform, Class) {
//Create Array of All HTML Tags
var allHTMLTags = document.getElementsByTagName(“*”);
//Loop through all tags using a for loop
for (i=0; i < allHTMLTags.length; i++) {
//Get all tags with the specified class name.
if (allHTMLTags[i].className == Class) {
if(myform.mycheckbox1.checked == true) {
allHTMLTags[i].style.backgroundColor = ‘#C39’;
}
else {
allHTMLTags[i].style.backgroundColor = ‘transparent’;
}
}
}
}
</script>
<form name=”myform”>
<input type=”checkbox” name=”mycheckbox1″ value=”value” onclick=”highlight3(this.form, ‘highlight’)”>
<span class=”highlight”> Highlight this text by checking the box </span>
Here it is in action: [url]http://littleduck.com/test2.html
So I want to have more checkboxes named mycheckbox2, mycheckbox3, etc. How can I add code in the script to cycle through all the checkboxes?
Thank you.