Example, loops all checkboxes on page with certain name and alerts if they are checked Note: masterform is the name of my <form name='masterform' ...> variable
for (var i = 0; i < document.masterform.elements.length; i++) { if (document.masterform.elements[i].type == 'checkbox') { if (document.masterform.elements[i].name.substring(0, 12) == 'chk_project_') { if (document.masterform.elements[i].checked) { alert('You Checked: ' + document.masterform.elements[i].name + ' Whos value is ' + document.masterform.elements[i].value); } } } }
A bit different than looping forms, this will loop all elements (like divs, spans, links...).
Collapse or Expand certain divs and alter link text
function toggle_wiki_headers(collapse) { //Toggle Header Content Div Display var divs = document.getElementsByTagName("div"); for (i=0; i < divs.length; i++) { id = divs[i].id; if (id.substring(id.length-9, id.length) == '__content') { if (collapse) { document.getElementById(id).style.display = 'none'; } else { document.getElementById(id).style.display = 'block'; } } } //Toggle Header [+]/[-] link display var hrefs = document.getElementsByTagName("a"); for (i=0; i < hrefs.length; i++) { id = hrefs[i].id; if (id.substring(id.length-6, id.length) == '__link') { if (collapse) { document.getElementById(id).innerHTML = '[+]'; } else { document.getElementById(id).innerHTML = '[-]'; } } } }
http://www.codelifter.com/main/javascript/capturemouseposition1.html