1

I have a page with a series of forms - all named same but IDs in pattern like:

<form name='myRadios' id='myRadios_1' />
<form name='myRadios' id='myRadios_2' />
<form name='myRadios' id='myRadios_3' />

I'm capturing the radio button via:

    $('input[type=radio]').change(function (event) {

But need to figure out which form holds the clicked button. At this point I'm working on appending the same ID iterator to the ID field of the radio button itself:

var targetForm = event.target.id.toString().split("_")[1];

But I don't see how I take that value and use it to bind to the correct form. Am trying variations along the lines:

var form = $("#myRadios_" + targetForm);
var form = $("[id=#myRadios_" + targetForm+ "]");
justSteve
  • 5,444
  • 19
  • 72
  • 137
  • This should answer your question: http://stackoverflow.com/questions/5376431/wildcards-in-jquery-selectors - includes link to docs for selectors – Tim Hobbs Apr 14 '13 at 21:27

1 Answers1

2
$('input:radio').on('change', function(){
   var $form = $(this).closest('form');
});
kayz1
  • 7,260
  • 3
  • 53
  • 56