I just ran into a problem where i am converting a select into <ul><li/></ul> format.
Now i take all the options, their values, html and classes and turn them into li.
That means the li get value attributes etc.
The problem at hand
It works perfectly fine when the options have integers (currently below 4 digits) and convert them. But i have another one where the select options have guids as values. When i try transform that all the values in the become zero i.e. value=”0″.
Does anyone have any ideas?
My code exactly:
//Extract listbox
$preferenceListBox.children().each(function () {
var $liToAdd = $liTemplate.clone();
console.log($(this).val());
$liToAdd.html($(this).html()).prop("value",$(this).val()).prop("disabled", $(this).prop("disabled"));
if ($(this).is("[disabled='disabled']") || $(this).is("[selected='selected']")) {
$liToAdd.addClass("disabled");
}
if ($(this).filter(":selected") > 0) {
$liToAdd.prop("disabled", "disabled");
}
$selectionList.append($liToAdd);
});
Update
Sample of converted list html:
<ul class="selectionList"><li value="0" class="ui-draggable ui-selectable">-Select-<b class="preferenceButton">+</b></li><li value="0" class="ui-draggable ui-selectable">Canberra Central<b class="preferenceButton">+</b></li>...</ul>
It was created from this select:
<select class="preferenceListBox noSelectItem" id="areaCodeList" multiple="multiple" name="areaCodeList" size="7" style="display: none; "><option disabled="disabled" class="disabled">-Select-</option><option value="24631a28-901d-4156-b6f6-2d2b3c10c9ec">Canberra Central</option>...</select>
Hmm…
http://www.w3schools.com/tags/att_li_value.asp
http://www.w3schools.com/tags/tag_li.asp
ps: did you think about using
idorclassattribute instead ofvalue?