I've looked at these posts: jQuery selector for inputs with square brackets in the name attribute Escape square brackets when assigning a class name to an element Square brackets meaning string wont work
But I still can't get jquery to properly handle a name with square brackets.
When I used jquery with a rails form_tag I had no problems because the name of the radio button was simply "option", without square brackets. When I switched to a rails form_for, rails included the object "resource" and thus the name of the radio button became "resource[option]". These square brackets caused jquery to stop working. As you'll note below, I tried using // to handle the brackets, but it still doesn't work.
This code with a form_tag worked:
$("input:radio[name='option']").click(function(){
if(this.value == 'no_<%= user.id %>' && this.checked){
$("#fields_<%= user.id %>").hide();
}
if(this.value == 'yes_<%= user.id %>' && this.checked){
$("#fields_<%= user.id %>").show();
}
});
The code below with form_for(@resource) does not work:
$("input:radio[name='resource\\[option\\]']").click(function(){
if(this.value == 'resource_option_no_<%= user.id %>' && this.checked){
$("#fields_<%= user.id %>").hide();
}
if(this.value == 'resource_option_yes_<%= user.id %>' && this.checked){
$("#fields_<%= user.id %>").show();
}
});
Any help would be appreciated. Thanks