3 * Transform <select> elements with only one single option into labels and
6 * Since disabled <select> elements will not be submitted with a form,
7 * instead this function transforms such elements into hidden <input>
8 * elements and adds a label which contains the text of the choice made
9 * through the <select>.
11 * Unlike its predecessor, this function operates on *all* <select>
12 * elements in the document.
15 $("select").each(function(i, select) {
16 if (select.options.length == 1) {
17 var $option = $(select.options[0]);
18 var $select = $(select);
19 var val = $option.val();
22 // get the id/css/display text and apply it to our new element
23 var display = $option.html()
24 var id = $select.attr('id');
25 var classes = $select.attr('class');
26 var $element = $("<span />").attr('id', id)
27 .attr('class', classes)
30 // add our new element right after the select and hide the dropdown
31 $select.after($element);