checkboxes - how to check them when they're dynamicaly named
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:
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
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!