Groups | Blog | Home
all groups > asp.net webcontrols > july 2003 >

asp.net webcontrols : RadioButtonLists and Javascript


ssarthur2 NO[at]SPAM yahoo.com
7/21/2003 3:02:42 PM
I have created an ASP.Net page that contains a RadioButtonList. I
want to access these radio buttons using Javascript. However when the
page renders, the application wraps the <input> tags inside a <span>
tag with the same name.

This makes the buttons difficult (if not impossible?) to access via
javascript. Any ideas? Am I trying to do mix two things that
Microsoft didn't intend to mix?

Code follows.

Thanks,
Steve



<script language=Javascript>
// The following does not work, since a span tag has no attribute
// named "value".
if (theForm.employeeIDType.value == "S")
{
// some code
}
</script>

<asp:radiobuttonlist id="employeeIDType" runat="server">
<asp:ListItem value="S" Selected=True>SSN</asp:ListItem>
<asp:ListItem value="G">Green Card</asp:ListItem>
</asp:radiobuttonlist>



This results in HTML as follows:

<span id="employeeIDType">
<input id="employeeIDType_0" type="radio" name="employeeIDType"
value="S" /><label for="employeeIDType_0">SSN</label>
<input id="employeeIDType_1" type="radio" name="employeeIDType"
value="G" /><label for="employeeIDType_1">Green Card</label>
Scott M.
7/21/2003 10:11:48 PM
Does the RadioButtonList have a "name" property as well as an "id" property.
If so, you could give the control a "name" that your JavaScript could use
and an "id" that the span tag would replicate.


[quoted text, click to view]

AddThis Social Bookmark Button