Solved

Access repeater checkboxes via javascript getElementByID

Posted on 2004-04-29
5
9,993 Views
Last Modified: 2012-06-27
My repeater is creating checkboxes, but it gives them a real long id, like
createWidgetControl_sharedUserControl_Repeater1__ctl1_chkRead

Is there a way to access these via javascript without hard coding that string?

The reason I ask is because I have a user control which is included in many pages and therefore the ID's of the checkboxes change depending on where it is included.

thanks in advance.
0
Comment
Question by:Rodney Helsens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
chisholmd earned 125 total points
ID: 10950431
Sure, If they are the only checkbox elements on the page you could do something like:

for(i=0;i<document.all.length;i++){
   if(document.all[i].type=='checkbox'){
           //do something
   }
}

What do you need to do with the checkboxes with your client side code?




0
 
LVL 9

Author Comment

by:Rodney Helsens
ID: 10950846
chisholmd,
thanks for the response.

The challenge is, I would like to emulate the 'select all/deselect' all type functionality BUT on a per row basis.

So the repeater would have 5 columns with a checkbox in each, and also have a button or control that when clicked, would select/deselect all checkboxes on that row using javascript.

I have the code to do it, but as I said in my original comment, asp.net assigns an ID to the checkboxes and I am not sure how to deal with that.

thanks.

 
0
 
LVL 9

Author Comment

by:Rodney Helsens
ID: 10950862
chisholmd,
I used your suggestion with some modification and got it working, thanks for jarring my brain!

function toggleCheckBoxes(isChecked, val)
{
var re = '_sharedAccessControl_Repeater1__ctl' + val + '_chk';
for(i = 0; i < document.all.length; i++)
   {
   elm = document.all[i];
   if (elm.type=='checkbox')
      {
      if (elm.id.indexOf(re) >= 0)
         {
         elm.checked = isChecked
         }
      }
   }
}
0
 
LVL 7

Expert Comment

by:chisholmd
ID: 10950997
Great!, If you only wanted to do one row then I assume the select/deselect all is contained in that row, maybe at the end. If so you could pass "this" from the button/link. Then from that reference you could walk up the DOM to the table row and loop through only that row looking for checkboxes.

function selectDeselectRow(btn_el){
      var td = btn_el.parent
      var tr = td.parent
       for(i=0;i<tr.all.length;i++){
             //if a checkbox is checked uncheck else check
       }
}

Or something like that but cross browser compatible :)
0
 
LVL 9

Author Comment

by:Rodney Helsens
ID: 10951120
Yeah, thanks I'll try that
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Select2 jquery help 9 100
If condition on Html with Asp 11 44
edit .asp files 5 49
ASP sending two datas 2 23
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question