我有一個radibutton列表。通過javascript從radiobuttonlist獲取值?
<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>
並獲得從電臺列表值我有一個函數:
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);
}
}
}
但它返回undefined。
我寫錯了什麼?
我在點擊按鈕時調用了這個函數。
建議我如果我可以在後臺代碼的幫助下做到這一點,儘管使用Javascript。
thanx它正在工作 – vikas