Solved

Radiobuttonlist client side javascript question

Posted on 2004-10-28
4,965 Views
Last Modified: 2008-01-09
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
0
Question by:Quintin79
    7 Comments
     
    LVL 6

    Expert Comment

    by:ryerras
    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
     
    LVL 1

    Author Comment

    by:Quintin79
    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
     
    LVL 15

    Expert Comment

    by:Thogek
    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
     
    LVL 6

    Expert Comment

    by:ryerras
    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
     
    LVL 1

    Author Comment

    by:Quintin79
    ryerras - yes.  that way i can loop thru it in javascript.
    0
     
    LVL 6

    Accepted Solution

    by:
    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
     
    LVL 1

    Author Comment

    by:Quintin79
    oh man is that all i can do ?  thats a let down.  anyway thanks - your answer is the go.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…
    This video discusses moving either the default database or any database to a new volume.

    913 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

    17 Experts available now in Live!

    Get 1:1 Help Now