Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the value of a radio button list 1

Status
Not open for further replies.

MaffewW

Technical User
Apr 9, 2002
438
GB
Hi

I'm calling a javascript function from an asp.net page and need to test a value. I'm running this bit of code..

Code:
alert(document.getElementById("rblUKResident").Value);

..so that I can test the value of a .net radio button control. The control has the values "Yes" and "No", but whichever one I select the alert always says 'undefined'. If I do the same test with a text box e.g.

Code:
alert(document.getElementById("txtName").Value);

..it works fine and returns the value. Can anyone tell me why and therefore how I can access the value of a .net radio button list in javascript.

Thanks a lot

P.s. I've tried posting a similar problem in the javascript forum and no-one seemed to be able to help.



Matt

Brighton, UK
 
Have a look at the View Source once the page has rendered. If there is a an element named "rblUKResident" (which sometimes isn't the case as ASP.NET can modify the client ID) then it's a javascript problem of how you are accessing the element (i.e. for radio buttons, you may have to get the value by a different method than just using .value).

Also, give your question some time to get answered in the JS forum - it was only asked 3 hours ago.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi

Thanks a lot for your reply. This is the actual code for the radio button list:

Code:
<asp:radiobuttonlist id="rblUKResident" runat="server" RepeatDirection="Horizontal">
							<asp:ListItem Value="Yes">Yes</asp:ListItem>
							<asp:ListItem Value="No">No</asp:ListItem>
						</asp:radiobuttonlist>

..and this is the code when I view the source of that page:

Code:
<TD style="WIDTH: 373px" bgColor="#f0f0f0">2) UK Resident</TD>
					<TD style="WIDTH: 170px" bgColor="#f0f0f0"><table id="rblUKResident" border="0">
	<tr>
		<td><input id="rblUKResident_0" type="radio" name="rblUKResident" value="Yes" /><label for="rblUKResident_0">Yes</label></td><td><input id="rblUKResident_1" type="radio" name="rblUKResident" value="No" /><label for="rblUKResident_1">No</label></td>
	</tr>
</table></TD>

How would I reference this control?

Cheers



Matt

Brighton, UK
 
Paste the second piece of code that you provided into youe post on the javascript forum - they'll tell you the best method of getting the value.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I've just tried referencing it as "rblUKResident_0" and it works! Great tip. Thanks very much - I've been looking at this code for ages..



Matt

Brighton, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top