Getting document.getElementByName with a substring
<p>With the constraint that you can't use jquery, what's the best way to get all element names that start with a specific string?  (These are checkboxes, and I want to clear all the others when one is checked. </p>

<p>My solution works, but it seems less than optimal; is there a better approach? </p>

<p>What I'm doing is putting the checkboxes within a div and getting all the children of the div, and then comparing their name to what I'm looking for.  Here's the javascript: </p>

<pre><code>&lt;script language="javascript" type="text/javascript"&gt;
function clearCheckboxes(name, id, divtag) {
   if (document.getElementById(id).checked == false) { 
         return; 
   }

   var listbox = document.getElementById(divtag);
   var list = listbox.childNodes;  
   for(var i = 0; i &lt; list.length; i++) {
      if (list[i].type != "checkbox") continue; 
      if (list[i].id == id) continue;
      if (list[i].name.substr(0, name.length) == name)
      {
            list[i].checked = false;
      }
   }
}
</code></pre>

<p>and then the html looks like this: </p>

<pre><code>&lt;div id="tag_div_2"&gt;
   &lt;input type="checkbox" name="tags_Type_4"  id="4" onclick="clearCheckboxes('tags_Type_',4,'tag_div_2');" /&gt;3 Stone Ring

   &lt;input type="checkbox" name="tags_Type_3"  id="3" onclick="clearCheckboxes('tags_Type_',3,'tag_div_2');" /&gt;Engagement Ring

   &lt;input type="checkbox" name="tags_Type_2"  id="2" onclick="clearCheckboxes('tags_Type_',2,'tag_div_2');" /&gt;Solitaire

   &lt;input type="checkbox" name="tags_Type_5"  id="5" onclick="clearCheckboxes('tags_Type_',5,'tag_div_2');" /&gt;Wedding Set
&lt;/div&gt;
</code></pre>
