0

I have html code with radio buttons and some common button. After click common button I copy this code with .clone and insert after with .after. In first block I have radio buttons with name like 'name', in second I change this name like '1name', in third -'2name' and etc. Moreover I have js code

    $('input[type=radio]').change(function(){
            var index= $(this).attr('rbgindex');
            var name = $(this).attr('name');
            $('.hid-'+name).remove();
            $(this).parent().after('<input class=hid-'+name+' type=hidden name='+name+index+' value='+index+' checked>');
    });

It should create hidden filed after change radio button. But I have problem with it. If I change radio button in firsy work, it work, but in another it doesn't work. What's wrong?

V-K
  • 1,297
  • 10
  • 28

1 Answers1

1

Use $(document).on('change') event for change event handling

$(document).on('change','input[type=radio]',function(){
      var index= $(this).attr('rbgindex');
      var name = $(this).attr('name');
      $('.hid-'+name).remove();
      $(this).parent().after('<input class=hid-'+name+' type=hidden name='+name+index+' value='+index+' checked>');
});
Dhara Parmar
  • 8,021
  • 1
  • 16
  • 27