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:
I used to call this function like so:
Just an idea, but is there any way you can keep the checkboxes named the same, but assign them different values?
<input type="checkbox" name="InvoiceRun" value="<%=rs.RecordID%>">
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.
Hope this helps,
nah, fraid not.
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!
OK, option #2 - not as elegant, but something to try:
for each checkbox, give it a class ID, something like this:
<input type="checkbox" name="<%="InvoiceRun_" & rs.RecordID%>" class="chkbox">
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!
Hope this helps,
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)