I have bind listbox using apex. Below is my code
JavaScript
x
8
1
<select id="{!$Component.multiselectPanel}:rightList"
2
class="multilist" multiple="multiple" size="{!size}"
3
style="width: {!width};">
4
<apex:repeat value="{!rightOptions}" var="option">
5
<option value="{!option.value}">{!option.label}</option>
6
</apex:repeat>
7
</select>
8
When I click on Top Button that time Selected Item move on top. For Example, In below Image when I clicked on top button that time ‘Location’ text become first then ‘Demo Site’ and other values are shown in listbox.
Here, I also put my JavaScript code for reference :
JavaScript
1
13
13
1
function(idList, idHidden) {
2
listBox = document.getElementById(idList);
3
4
var len = listBox.options.length;
5
6
if (len > 0 && listBox.options[0].selected == true) {
7
return;
8
}
9
else {
10
listBox.insertBefore(listBox.options[0],
11
listBox.options[listBox.selectedIndex]);
12
}
13
}
How can we achieve this?
Advertisement
Answer
Try this, hope it helps you
JavaScript
1
2
1
listBox.insertBefore(listBox.options[listBox.selectedIndex], listBox.childNodes[0]);
2