Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  56] [ 1]  / answers: 1 / hits: 42530  / 12 Years ago, wed, september 26, 2012, 12:00:00

I have a radibutton list.



          <asp:RadioButtonList ID=RadioButtonList1 runat=server 
RepeatDirection=Horizontal RepeatLayout=flow >
<asp:ListItem Selected=True Text =Yes Value=0></asp:ListItem>
<asp:ListItem Text =No Value=1></asp:ListItem>
</asp:RadioButtonList>


And to get the value from radio list I have a function :



 function getvalueofradiolist() {

var radiolist = document.getElementById('<%= RadioButtonList1.ClientID %>');
var rblName = radiolist.name;
var radio = document.getElementsByName(rblName);

for (var x = 0; x < radio.length; x++) {
if (radio[x].checked) {
alert(Selected item Value + radio[x].value);
}
}
}


But it returns undefined.



Did I write something wrong?



I am calling this function on button click.



Suggest me If I can do this with the help of code behind in spite of Javascript.


More From » asp.net

 Answers
49
<form runat=server>
<asp:RadioButtonList ID=RadioButtonList1 runat=server
RepeatDirection=Horizontal RepeatLayout=flow >
<asp:ListItem Selected=True Text =Yes Value=0></asp:ListItem>
<asp:ListItem Text =No Value=1></asp:ListItem>
</asp:RadioButtonList> </form>
<p id=button onclick=getvalue()>click me</p>

<script type=text/javascript>
function getvalue(){
alert($('#<%=RadioButtonList1.ClientID %> input[type=radio]:checked').val());
}
</script>

[#82909] Monday, September 24, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
warren

Total Points: 679
Total Questions: 115
Total Answers: 78

Location: Antigua and Barbuda
Member since Sat, Apr 24, 2021
3 Years ago
;