javascript to trigger change

64 Views Asked by At

I have a javascript query that replicates a select drop down as radio buttons and when the button is clicked it changes the value of the drop down. This problem I have is that there is an onchange event in the drop down that is not being triggered. I know I can trigger this within the javascript but no matter where I put the trigger it's not working. Javascript is below.

$(function () {

  $('.radioSelect').each(function (selectIndex, selectElement)  {
   
    var select = $(selectElement);
    var container = $("<fieldset class='radio-inline' />");
    select.parent().append(container);
    container.append(select);
    
    select.find('option').each(function (optionIndex, optionElement) {
      var radioGroup = select.attr('id');
      var label = $("<label  class='radio-label'/>");
      container.append(label);
      $("<span>" + this.textContent + "</span><br />").appendTo(label)
      $("<input type='radio' name='" + radioGroup + "' /><img src='images/images.jpg'>")
          .attr("value", $(this).val())
          .click((function () { select.val($(this).val()); })) //radio updates select - see optional below
          .appendTo(label);
  
    });
    
    select.change((function () { //select updates radio
      $("input[name='" + select.attr('id') + "'][value='" + this.value + "']").prop("checked", true);
   
    }));
  });
  
});

0

There are 0 best solutions below