checkboxes - how to check them when they're dynamicaly named
hey guys
I have an ASP page which displays a recordset - each record in the rs has a dynamically named checkbox (ie. <%="InvoiceRun_" & rs.RecordID%>. It all works fine, except I have a little JS function that used to check all my checkboxes, back when my checkboxes were statically named:
function checkall(formname,checkname,thestate){
var el_collection=eval("document.forms."+formname+"."+checkname)
for (c=0;c<el_collection.length;c++)
el_collection[c].checked=thestate
}
What I'd like to know is whether anyone has any clue how to get it to check all the boxes now that they're not all called "InvoiceRun". They all still START with "InvoiceRun", but end in the recordID. Some kind of wildcard would be good, only my javascript doesn't run to that....
This way, you can still reference the checkboxes using document.formname.InvoiceRun[c], as well as uniquely identifying all the checkboxes by "value=". This may or may not work for you depending on how the rest of your page uses these checkboxes, but it's hard to say more without knowing more specifics about your page.
I need the names of the checkboxes to be unique due to a bunch of ASP/SQL updates going on on the page, which require them to be unique. That took me about a week to write, so no way am I gonna change it now!
This class ID doesn't have to be linked to anything, just a unique identifier for all checkboxes. This way, you can find & check all chekcboxes like this (VBScript, sorry!):
for each element in document.formname.elements
if element.classname="chkbox" then
element.checked = true
end if
next
This isn't elegant - it's actually rather ugly. It feels like more of a workaround than a solution, but it'll work. I'm sure there's a lot of better ways to do this though, so anyone else with ideas, go right ahead!
Bookmarks