【ASP.NET】RadioButtonListをJavaScriptで操作する

user-pic
0 Clip to Evernote



RadioButtonListは、以下の様にリスト構造になっているので、個々のボタンにidがない。


<asp:radiobuttonlist id="rblstdidname" runat="server" RepeatDirection="Horizontal">   <asp:ListItem Value="A">one</asp:ListItem>   <asp:ListItem Value="B">two</asp:ListItem>   <asp:ListItem Value="C">three</asp:ListItem> </asp:radiobuttonlist>


個々のボタンが選択されているかどうか、JavaScriptで判断したかったが、idがないので(RadioButtonListのidでやっても当然できない)無理かなと思っていたが、生成されたaspxページのソースを見てみると、RadioButtonListの所は、こうなっていた。


<table id="rblstdidname"><tr>
  <td>
    <input id="rblstdidname_0" type="radio" name="rblstdidname" value="A"/>
    <label for="rblstdidname_0">one</label>
  </td>
  <td>
    <input id="rblstdidname_1" type="radio" name="rblstdidname" value="B"/>
    <label for="rblstdidname_1">two</label>
  </td>
  <td>
    <input id="rblstdidname_2" type="radio" name="rblstdidname" value="C"/>
    <label for="rblstdidname_2">three</label>
  </td>
</tr></table>

よく考えれば、最後はhtmlになるのだから、あたりまえだが、盲点だった。
ちなみに、こういう_○みたいな連番になるのは、IEだけかもしれない。 (ほかのブラウザでは確認していない。確認したのは、IE6)



■関連記事


ドミノ・ピザ【PC向けサイト】 楽天トラベル株式会社 NEC Direct ・NECダイレクト