0

別のラジオボタン選択からの回答に応じて、ラジオボタンリストを無効または有効にしようとしています。これは私がまとめたコードですが、うまく機能しませんでした:

<script type="text/javascript">
        // enable May we contact your present employer if Employed Now is yes

        function EmployedNowYes(answer) {

            if (answer == "Yes") {
                document.getElementById("<%=ContactEmployer.ClientID %>").enabled = true;
            }

            if (answer == "No") {
                document.getElementById("<%=ContactEmployer.ClientID %>").enabled = false;
            }

        }

    </script>
Are you employed now?
                <asp:RadioButtonList ID="EmployedNow" runat="server" RepeatDirection="Horizontal" >
                    <asp:ListItem Value="Yes" onclick ="EmployedNowYes(this.value)">Yes</asp:ListItem>
                    <asp:ListItem Value="No" onclick ="EmployedNowYes(this.value)">No</asp:ListItem>
                </asp:RadioButtonList>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ControlToValidate="EmployedNow"
                    ErrorMessage="* Required field." ForeColor="Red"> </asp:RequiredFieldValidator>
            </td><td class="style42" valign="top">
                May we contact your present employer:
                <asp:RadioButtonList ID="ContactEmployer" runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem >Yes</asp:ListItem>
                    <asp:ListItem >No</asp:ListItem>
                </asp:RadioButtonList>
                            </td>
4

1 に答える 1

0

私はJavascriptであなたが書く必要があることを発見しました...

document.getElementById("<%=ContactEmployer.ClientID %>").disabled = false;
document.getElementById("<%=ContactEmployer.ClientID %>").disabled = true;

また、無効にされたコントロールの値がポストバックのコードビハインドに戻されない場合もあります。

于 2013-01-18T08:40:42.667 に答える