When trying to toggle the visibility of my TextBox
based on a selected value in a RadiobuttonList
, I initially wrote the following code:
$("#<%= rbtnIsPFEnabled.ClientID %>").click(function () {
pfno = $("#<%= txtPFNo.ClientID %>");
if ($("#<%= rbtnIsPFEnabled.ClientID %> input:checked").val() == "Yes") {
pfno.css("dispay") = "block";
}
else
pfno.css("dispay") = "none";
});
Although I successfully achieved my goal using JQuery.show()
and JQuery.hide()
, I was not completely satisfied because I wanted to understand why my initial approach failed. Furthermore, I questioned if it was possible to simplify my code by using something like this
instead of repeating
$("#<%= rbtnIsPFEnabled.ClientID %>")
a second time.
I experimented with $(this+" input:checked").val()
and
$(this.toString()+" input:checked").val()
, but unfortunately, neither worked, so I ended up duplicating the selector in my code.