I'm new to JQuery and learning this myself. I want to toggle my display using the least amount of code. My code currently works but I'm sure there is a better way. Cheers.
<div id="container">
<asp:Panel runat="server" ID="pnlHeader">
<asp:RadioButton runat="server" ID="radOne" GroupName="myRadGroup" Text="One" value="1" onclick="ToggleMyDisplay();" />
<asp:RadioButton runat="server" ID="radTwo" GroupName="myRadGroup" Text="Two" value="2" onclick="ToggleMyDisplay();" />
<asp:RadioButton runat="server" ID="radThree" GroupName="myRadGroup" Text="Three" value="3" onclick="ToggleMyDisplay();" />
<asp:RadioButton runat="server" ID="radFour" GroupName="myRadGroup" Text="Four" value="4" onclick="ToggleMyDisplay();" />
<div>
<label for="ddlOne" id="lblOne">DDL One:</label>
<asp:DropDownList ID="ddlOne" runat="server"></asp:DropDownList>
</div>
</asp:Panel>
<asp:Panel runat="server" ID="pnlOne" Style="display: none;">
<div>
<label for="ddlTwo">To:</label>
<asp:DropDownList ID="ddlTwo" runat="server"></asp:DropDownList>
</div>
</asp:Panel>
<asp:Panel runat="server" ID="pnlTwo" Style="display: none;">
<div>
<label for="txtMyText">My Text:</label>
<asp:TextBox ID="txtMyText" runat="server"></asp:TextBox>
</div>
</asp:Panel>
<asp:Panel runat="server" ID="pnlThree" CssClass="fieldsLarge" Visible="true">
<table>
<tr>
<td rowspan="3" style="width: 775px">
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>
</td>
<td style="text-align: right;">
<asp:Button ID="btnContinue" runat="server" Text="Button" Visible="false" />
</td>
</tr>
<tr>
<td style="text-align: right;">
<asp:Button ID="btnExit" runat="server" Text="Button" Visible="false" />
</td>
</tr>
<tr>
<td style="text-align: right;">
<asp:Button ID="btnSave" runat="server" Text="Button" Visible="false" />
</td>
</tr>
</table>
</asp:Panel>
Here is the JQuery I have at the moment
function ToggleMyDisplay() {
if ($("#radOne").attr("checked") !== "undefined" && $("#radOne").attr("checked") === "checked") {
MyLabel.text('First Radio Selected:');
$("#pnlOne").hide();
$("#pnlTwo").hide();
$("#btnContinue").hide();
$("#btnExit").hide();
$("#btnSave").show();
}
else if ($("#radTwo").attr("checked") !== "undefined" && $("#radTwo").attr("checked") === "checked") {
MyLabel.text('Second Radio Selected:');
$("#pnlOne").hide();
$("#pnlTwo").hide();
$("#btnContinue").hide();
$("#btnExit").hide();
$("#btnSave").show();
}
else if ($("#radThree").attr("checked") !== "undefined" && $("#radThree").attr("checked") === "checked") {
MyLabel.text('Third Radio Selected:');
$("#pnlOne").show();
$("#pnlTwo").show();
$("#btnContinue").show();
$("#btnExit").hide();
$("#btnSave").show();
}
else if ($("#radFour").attr("checked") !== "undefined" && $("#radFour").attr("checked") === "checked") {
MyLabel.text('F:');
$("#pnlOne").show();
$("#pnlTwo").show();
$("#btnContinue").show();
$("#btnExit").hide();
$("#btnSave").show();
}
}