Solved

How to get radiobuttonlist selected value in aspx?

Posted on 2009-05-05
4
2,306 Views
Last Modified: 2012-05-06
Hi

I need to get the selected value of a radio button list in aspx by javascript.

But it is undefined. I tried ctl01_op too as I saw the id changed to it in html.
function cald() {
var radioList = document.getElementsByName("op");
            for( var i=0; i < radioList.length; ++i)
            {
               if( radioList[i].checked)
              {
                   alert("Checked item: " + radioList[i].value)
              }
            }
}
 
 
<asp:RadioButtonList Runat="server" ID="op" name="op" RepeatDirection="Horizontal" TextAlign="Left" onchange='cald()'>
<asp:ListItem Value="*" Selected="true">*</asp:ListItem>
<asp:ListItem Value="/">/</asp:ListItem>
</asp:RadioButtonList>

Open in new window

0
Comment
Question by:techques
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:ajolly
ID: 24305408
use

var radioList = document.getElementsById(<%=op.ClientID%>);
0
 

Author Comment

by:techques
ID: 24310687
the js error said it does not support this property or method.

0
 
LVL 7

Accepted Solution

by:
ajolly earned 50 total points
ID: 24311212
try with onclick event.
The following code is working and tested.
<%@ Page Language="C#" AutoEventWireup="False" CodeFile="Success2.aspx.cs" Inherits="Success2" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 
    <script type="text/javascript">
        function cald()
        {
            var radioList = document.getElementsByName("op");
            for (var i = 0; i < radioList.length; ++i)
            {
                if (radioList[i].checked)
                {
                    alert("Checked item: " + radioList[i].value)
                }
            }
        }
    </script>
 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:RadioButtonList runat="server" ID="op" name="op" RepeatDirection="Horizontal"
            TextAlign="Left" onclick="cald();">
            <asp:ListItem Value="*" Selected="true">*</asp:ListItem>
            <asp:ListItem Value="/">/</asp:ListItem>
        </asp:RadioButtonList>
    </div>
    </form>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:techques
ID: 31578041
excellent!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Angular2 remove duplicates 11 24
ASP.NET generate check digit for ITF-14 and EAN-13 barcodes 4 34
Error Handler 8 42
Drag & Drop Error 5 31
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 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