cmoreira

Convert Dropdown into Select (TTShowcase)

Feb 23rd, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery('[id^=_aditional_info_custom_boolean]').each(function(i, select){
  2.     var select = jQuery(this);
  3.     select.find('option').each(function(j, option){
  4.        if (j > 0) {
  5.         var option = jQuery(this);
  6.         // Create a radio:
  7.         var radio = jQuery('<input type="radio" />');
  8.         // Set name and value:
  9.         radio.attr('name', select.attr('name')).attr('id', select.attr('name')+j).attr('value', option.val());
  10.         // Set checked if the option was selected
  11.         if (option.attr('selected')) radio.attr('checked', 'checked');
  12.         // Insert radio before select box:
  13.         select.before(radio);
  14.         // Insert a label:
  15.         select.before(
  16.           jQuery("<label />").attr('for', select.attr('name')+j).text(option.text())
  17.         );
  18.         // Insert a \n:
  19.        // select.before("<br/>");
  20.     }});
  21.     select.remove();
  22. });
Advertisement
Add Comment
Please, Sign In to add comment