473,395 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

RadioButtonList and Javascript

trying to get a javascript attached to a DataGrid RadioButtonList. I
have a similar thing working for a DDL so i copied that for the RBL.
It "errors" when i am trying to get the current selected value for the
RBL.
code in ItemDataBound:

rblDC.Attributes.Add("onClick", "rblDC_onClick('" + lblDC.ClientID +
"', '" + rblDCodes.ClientID + "', '" + e.Item.ItemType + "')");

javascript:

function rblDC_onClick(lblDCId, rblDCId, eiT)
{
var lblDC = document.getElementById(lblDCId);
var rblDC = document.getElementById(rblDCId);
var rblDCSelection = rblDC.options[rblDC.selectedIndex].value); <--
JS error
if (lblDC.innerText == rblDCSelection)
"do stuff"
}

the error i get says:
"options" is null or is not an object.
which, to noob me, says that it doesn't have a valid rblDC. not sure
though. could be a syntax error of sorts.

thank you
troy

Nov 19 '05 #1
5 6224
a radio button list renders as a table of ID=ClientID, with an <input
type=radio> for each radio button. the buttons are named ClientID, and given
id of ClientID + "_" + index.

so adding a onclick is to the table and tables do not have options, thus
your error.

you need onclick event for each radio button, and check checked property.
try

function rblDC_onClick(lblDCId, rblDCId, eiT)
{
var lblDC = document.getElementById(lblDCId);
var rblDCs = document.getElementsByName(rblDCId);
var rblDCSelection = "";
for (var i in rblDCs)
{
if (rblDCs[i].checked)
{
rblDCSelection = rblDCs[i].value;
break;
}
}
if (lblDC.innerText == rblDCSelection)
"do stuff"
}

-- bruce (sqlwork.com)
<di*******@msn.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
trying to get a javascript attached to a DataGrid RadioButtonList. I
have a similar thing working for a DDL so i copied that for the RBL.
It "errors" when i am trying to get the current selected value for the
RBL.
code in ItemDataBound:

rblDC.Attributes.Add("onClick", "rblDC_onClick('" + lblDC.ClientID +
"', '" + rblDCodes.ClientID + "', '" + e.Item.ItemType + "')");

javascript:

function rblDC_onClick(lblDCId, rblDCId, eiT)
{
var lblDC = document.getElementById(lblDCId);
var rblDC = document.getElementById(rblDCId);
var rblDCSelection = rblDC.options[rblDC.selectedIndex].value); <--
JS error
if (lblDC.innerText == rblDCSelection)
"do stuff"
}

the error i get says:
"options" is null or is not an object.
which, to noob me, says that it doesn't have a valid rblDC. not sure
though. could be a syntax error of sorts.

thank you
troy

Nov 19 '05 #2
thank you for replying Bruce:
perhaps i am misunderstanding but I am adding the Attribute for each
item/row on the DataGrid at ItemDataBound time.

If I do need to check the index, it then confuses me why the exact same
code works perfectly for my DDL, where I don't have to check the index.

Troy

Nov 19 '05 #3
the drop drown renders as a <select>. in the browser dom a select has an
options array, one for each option caontained in the select. a option has a
value and text propery (also a selected which indicates if this is the
seledted item)

there is no radio list in the browser, asp.net just renders a table with
radio buttons. in the browser, if the radio buttons have the same name, they
are treated as exclusive. their is id need to be unique. here is a simple
radio list:

<asp:RadioButtonList id="myList" runat="server">
<asp:ListItem Value="1">option 1</asp:ListItem>
<asp:ListItem Value="2">option 2</asp:ListItem>
</asp:RadioButtonList>

will render:

<table id="myList" border="0">
<tr>
<td>
<input id="myList_0" type="radio" name="myList" value="1" />
<label for="myList_0">option 1</label>
</td>
</tr>
<tr>
<td>
<input id="myList_1" type="radio" name="myList" value="2" />
<label for="myList_1">option 2</label>
</td>
</tr>
</table>

to get a collection of the radio buttons, you get all form inputs with the
name myList.

document.getElementsByName("myList");

to figure out the selected one, you look looking for a checked one.

note: if you want to write client script, you should study the html dom.

-- bruce (sqlwork.com)


<di*******@msn.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
thank you for replying Bruce:
perhaps i am misunderstanding but I am adding the Attribute for each
item/row on the DataGrid at ItemDataBound time.

If I do need to check the index, it then confuses me why the exact same
code works perfectly for my DDL, where I don't have to check the index.

Troy

Nov 19 '05 #4
thank you again bruce.

being new at this I was not aware that a RBL isn't really 1 element but
a group of individual elements. good to know. I see why the DDL is
different.

So, your code suggestion now, i believe, makes sense.
To go over it again then:
- the code:
var rblDCs = document.getElementsByName(rblDCId);

is returning the names of the elements of the table (rblDC_0, rblDC_1
.... )

- the code:
for (i in rblDCs)

is spinning through those names trying to figure out which one has
been checked.
correct?

however, unfortunately there has to be a however, the code to get the
elementsbyname doesn't seem to be returning the names .. but something
else like attributes of the table and such (like "length").

is there a step that I am missing?

thank you
troy

Nov 19 '05 #5
also, I noticed that if the names of the elements are not the same.
The table name is
itg__ctl3_rblDC
and the names of the individual RBL elements are
itg:_ctl3:rbldc

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Suresh.P.R | last post by:
Hi, While using the RadioButtonList control, that I populated in the runtime, I am not able to get the selected item in the javascript while referring document.Form.RadioButtonList.value. ...
2
by: sramruttun | last post by:
hi I have a checkbox and a radiobuttonlist (the radiobuttonlist contains 2 items) in my form. The radiobuttonlist has its visible property set to false at design time. At run time, when the...
2
by: Sean | last post by:
Hi .... I have a radiobutton list and a label in a webform. <asp:radiobuttonlist id="one" runat="server" CssClass="text" AutoPostBack="False" RepeatDirection="Horizontal"> <asp:ListItem...
2
by: mg | last post by:
After a selection is made in the following RadioButtonList <asp:RadioButtonList id="RadioButtonList1" runat="server"> <asp:ListItem Value="Y"></asp:ListItem> <asp:ListItem...
5
by: DotNetGruven | last post by:
Anyone have any pointers on how to set the Value and Selected attributes in a ListItem in a RadioButtonList that is in a DataGrid? Here's what I have ------DataGrid------ -- BoundColumn 0 --...
6
by: DotNetGruven | last post by:
I have a webform that has a DataGrid on it with a RadioButtonList in each row. It is a simple On & Off. When the User Clicks on either of the RadioButtons, I need to postback to the server and...
0
by: Ryan Taylor | last post by:
Hello. I am having another issue. I need to execute some JavaScript whenever a radio button is clicked. I am currently using a RadioButtonList control to generate the radio buttons because of...
2
by: Alphonse Giambrone | last post by:
Hi all, I have two radiobuttonlist controls on a page. When a user checks 'No' for rblDeleted, I want to automatically set rblSendCard to 'No' and disable it. The javascript function I wrote to...
2
by: rishi pariahr via .NET 247 | last post by:
how to make validation on items of radiobuttonlist for checked or not in jsp,when these items are populated from database. -------------------------------- From: rishi pariahr ...
1
by: novice_developer | last post by:
Hi All, there is a radiobuttonlist having 2 list items (state & zipcode). when i select state radiobutton the zipcode textbox should be disabled and when i select a zipcode radiobutton the state...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.