More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Sunday, 3 January 2016 9:16:49 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 519

JavaScript - Get RadioButtonList selected value

There are many ways to get RadioButtonList selected value. For example:
Quote:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Height="174px"
Width="117px">
<asp:ListItem Value="1">one</asp:ListItem>
<asp:ListItem Value="2">two</asp:ListItem>
<asp:ListItem Value="3">three</asp:ListItem>
<asp:ListItem Value="4">four</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txt1" runat="server"></asp:TextBox>

<script type="text/javascript">
function GetRadioButtonValue(id) {
var radio = document.getElementsByName(id);
for (var j = 0; j < radio.length; j++) {
if (radio[j].checked)
document.getElementById('txt1').value=radio[j].value;
}
}
</script>

CS code:

protected void Page_Load(object sender, EventArgs e)
{

RadioButtonList1.Attributes.Add("onclick", "GetRadioButtonValue('RadioButtonList1');");

}


But there is a simple one-line way:
Code:
            var radioButtonListSelectedValue = $('#<%=RadioButtonList1.ClientID %> input[type=radio]:checked').val();

Edited by user Sunday, 3 January 2016 9:17:50 PM(UTC)  | Reason: Not specified

Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.