开发者

radio button click doesn't work

I have two radio buttons on my MVC page. When I click on 'Yes' button it enables the textbox but when I click on 'N开发者_Python百科o' it doesn't disable the textbox. What could be the problem?

    $('#rdoDate').click(function () {
        debugger;
        switch ($(this).val()) {
            case 'N':
                $("#txtDate").attr("disabled", true);
                break;
            case 'Y':
                $("#txtDate").removeAttr("disabled");
                break;
        }
    });

   <%=Html.RadioButton("rdoDate","Y")%><label>Yes</label> 
    <%=Html.RadioButton("rdoDate", "N", true)%><label>No</label>

<%: Html.TextBoxFor(model => model.txtDate, new { id = "txtDate", disabled = true })%> 


You can't define two same ID on a html page. If "rdoDate" is an ID, you'll have to define an other one for the second line, like :

<%=Html.RadioButton("rdoDateY","Y")%><label>Yes</label> 
<%=Html.RadioButton("rdoDateN", "N", true)%><label>No</label>

But if it's a name, the problem is in your Js code, where you try to access ID element (via #) instead of name elements (I don't know Html.RadioButton). If it's the case, you should locate your element like :

$('input[name="rdoDate"]').click (...);

Hope this helps :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜