Solved

Access repeater checkboxes via javascript getElementByID

Posted on 2004-04-29
5
9,974 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
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
chisholmd earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Yeah, thanks I'll try that
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now