PDA

View Full Version : سوال: نمایش مقدار RadioButtonList ایجاد شده در ASP.NET توسط جاوا اسکریپت در سمت کاربر



meisam1366
دوشنبه 02 خرداد 1390, 15:20 عصر
با سلام خدمت دوستان!

سوال من اینه که چطور میشه مقدار انتخاب شده یک RadioButtonList رو که توی ASP.net ایجاد کردیم، در سمت کاربر توسط جاوا اسکریپت با یه Alter نمایش بدیم.

من کد زیر رو استفاده کردم ولی جواب نداد:

var radio = document.getElementById('<%=RadioButtonList1.ClientID%>');
var r = radio.value;
alert('Selected Item Value is: "' + r + '"');

.
ممنون میشم راهنمایی کنید.

arash63
پنج شنبه 02 تیر 1390, 13:29 عصر
سلام

از کد زیر استفاده کن :




<script type="text/javascript">
function getvalue() {
var inputs = document.getElementById('<%=RadioButtonList1.ClientID %>').getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].checked) {
alert(inputs[i].value);
break;
}
}
}
</script>
<div>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="Item1" Value="1"></asp:ListItem>
<asp:ListItem Text="Item2" Value="2"></asp:ListItem>
</asp:RadioButtonList>
<a href="#" onclick="getvalue()">Get Selected Value</a>
</div>


موفق بایشد .