2012-05-13 5 views
1

ラジオボタンリストでJQueryを使用して選択した項目の値を取得しようとしています。私は2つのラジオボタンリストを持っていて、私は第1ラジオボタンリストから何か問題があればそれを得ています。しかし、2番目のドロップダウンを選択すると、同じ最初のドロップダウン結果がアラートに表示されます。jqueryをキャプチャするラジオボタンリストの選択値

jQueryのselectorsの上に移動してください

$("#<%=RBLTechnology.ClientID%> input").change(function() { 

       var ProjectArchitecture = $("input[@name=RBLTechnology]:checked").val(); 
alert("Selected Project Architecture Layer is " + ProjectArchitecture); 
          }); 

      $("#<%=RBLforService.ClientID%> input").change(function() { 
       var ServiceLayer = $("input[@name=RBLforService]:checked").val(); 
       alert("Selected Service Layer is " + ServiceLayer); 

      }); 



<asp:RadioButtonList ID="RBLTechnology" runat="server" RepeatDirection="Horizontal"> 
        <asp:ListItem Selected="True" Value="ASP.NET webforms">ASP.NET webforms</asp:ListItem> 
        <asp:ListItem Value="ASP.NET MVC">ASP.NET MVC</asp:ListItem> 
        <asp:ListItem Value="SilverLight">SilverLight</asp:ListItem> 
        <asp:ListItem Value="WPF">WPF</asp:ListItem> 
       </asp:RadioButtonList> 


    <asp:RadioButtonList ID="RBLforService" runat="server" RepeatDirection="Horizontal"> 
         <asp:ListItem Selected="True" Value="Class Library Service">Class Library Service</asp:ListItem> 
         <asp:ListItem Value="Web Service">Web Service</asp:ListItem> 
         <asp:ListItem Value="WCF Service">WCF Service</asp:ListItem> 
         <asp:ListItem Value="WCF RIA Service">WCF RIA Service</asp:ListItem> 
        </asp:RadioButtonList> 

答えて

2

を提案してください。私がこれまで見たものから

$("#<%=RBLTechnology.ClientID%>"), $("#<%=RBLforService.ClientID%>") 

$("input[@name=RBLforService]:checked"), $("input[@name=RBLforService]:checked") 

すべき

$("#<%=RBLTechnology.ClientID%> input"), $("#<%=RBLforService.ClientID%> input") 

ニーズが

$("input[name='RBLforService']:checked"), $("input[name='RBLforService']:checked") 
0
<asp:RadioButtonList ID="rblRequestType"> 
     <asp:ListItem Selected="True" Value="value1">Value1</asp:ListItem> 
     <asp:ListItem Value="Value2">Value2</asp:ListItem> 
    </asp:RadioButtonList> 
する必要があります

このようにリスト項目を(チェックしてもしなくても)コントロールできます。

var radio0 = $("#rblRequestType_0"); 
var radio1 = $("#rblRequestType_1"); 

if (radio0.checked){ 
// do something 
} 
if (radio1.checked){ 
// do something 
} 
関連する問題