Radiobuttonlist client side javascript question

OK

in HTML if i want to find the length or loop through an array of radio buttons in the browser i can usually go document.getElementById("arrayName").length;  cant I?

when you create a radiobuttonlist in asp.net it creates the correct radio tags on client side but it also surrounds them in a table with the same name.  you know that by naming the radios all the same it creates an array of the radios but asp.net throws in a table of the same name and i cant seem to access the radio buttons.

when i go document.getElementById("arrayName") it returns the table and therefore i cant get the radios.

any ideas on how to sort this one out

thanks in advance
LVL 1
Quintin79Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ryerrasConnect With a Mentor Commented:
hmm ok. Nothing cant be done in javascript, use this following two lines to find the length of the tables, when i say length of the table, that is number of rows,

var rbListTable = document.getElementById("RadioButtonList1").childNodes[0];
var tableRows = rbListTable.childNodes;
var tabLen= tableRows.length

After you get that, you know what you have to do, loop through from 0 to tabLen-1
0
 
ryerrasCommented:
hmm. If you open the View Source for the web page, you would see that, asp.net generates unique id's for each radio button in the list, and they will be in certain order. If your radioButtonList id is "arrayName", then lets say you have 3 radio buttons in the list, then the id's will be "arrayName_0", "arrayName_1" and "arrayName_2".

So to access the first radio button, you should use document.getElementById("arrayName_0");
0
 
Quintin79Author Commented:
yes i know this and its the very last option.  the reason is that in most cases the radiobutton list will be of any size it wants so i wont know how many rb objects i have to loop through.  
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ThogekCommented:
Instead of
    document.getElementById("arrayName")
have you tried
    document.forms[0].arrayName
?  (Might need to check the client-side View Source to verify the common radio button name -- that's name, not ID -- for this.)
0
 
ryerrasCommented:
I do not understand your question. What do you want to achieve? Length of the radio buttonlist, you mean how many radio buttons in the list?
0
 
Quintin79Author Commented:
ryerras - yes.  that way i can loop thru it in javascript.
0
 
Quintin79Author Commented:
oh man is that all i can do ?  thats a let down.  anyway thanks - your answer is the go.
0
All Courses

From novice to tech pro — start learning today.