View Full Version : سوال: بررسی مقدار RadioButtonList توسط جاوا اسکریپت
meisam1366
دوشنبه 02 خرداد 1390, 14:13 عصر
با سلام خدمت دوستان!
سوال من اینه که چطور میشه مقدار انتخاب شده یک RadioButtonList رو که توی ASP.net ایجاد کردیم، در سمت کاربر توسط جاوا اسکریپت با یه Alter نمایش بدیم.
من کد زیر رو استفاده کردم ولی جواب نداد:
var radio = document.getElementById('<%=RadioButtonList1.ClientID%>');
var r = radio.value;
alert('Selected Item Value is: "' + r + '"');
.
ممنون میشم راهنمایی کنید.
J.Masomi
دوشنبه 02 خرداد 1390, 14:48 عصر
با سلام
مشکل شما اینه که id تمام RadioButton هات احتمالاً برابره. باید از getElementsByTagName استفاده کنی.
meisam1366
دوشنبه 02 خرداد 1390, 15:22 عصر
مشکل شما اینه که id تمام RadioButton هات احتمالاً برابره. باید از getElementsByTagName استفاده کنی.
میشه یک مقدار بیشتر توضیح بدین؟
ضمنا وقتی Source View صفحه رو میبینم، id هرکدوم از رادیو باتن ها برابر نیست و به این صورته:
<table id="ctl00_ContentPlaceHolder1_RadioButtonList1" style="font-weight: bold;" border="0">
<tbody><tr>
<td><input id="ctl00_ContentPlaceHolder1_RadioButtonList1_0" name="ctl00$ContentPlaceHolder1$RadioButtonList1" value="20" type="radio"><label for="ctl00_ContentPlaceHolder1_RadioButtonList1_0">انتخاب اول</label></td>
</tr><tr>
<td><input id="ctl00_ContentPlaceHolder1_RadioButtonList1_1" name="ctl00$ContentPlaceHolder1$RadioButtonList1" value="21" type="radio"><label for="ctl00_ContentPlaceHolder1_RadioButtonList1_1">انتخاب دوم</label></td>
</tr><tr>
<td><input id="ctl00_ContentPlaceHolder1_RadioButtonList1_2" name="ctl00$ContentPlaceHolder1$RadioButtonList1" value="22" type="radio"><label for="ctl00_ContentPlaceHolder1_RadioButtonList1_2">انتخاب سوم</label></td>
</tr>
</tbody></table>
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.