»
EnglishFrenchVietnamese

Print - Sorted Items - JavaScriptBank.com

Full version: jsB@nk » Form » Dropdown » Sorted Items
URL: https://www.javascriptbank.com/sorted-items.html

Sorted Items © JavaScriptBank.comWhen visitors click the buttons, this JavaScript will sort the items in the listbox.

Full version: jsB@nk » Form » Dropdown » Sorted Items
URL: https://www.javascriptbank.com/sorted-items.html



JavaScript
<SCRIPT>OrgSel=new Array()S=document.forms[0].SelectNamefor(x=0;x<S.length;x++){OrgSel[x]=S.options[x].value}function ShfSel(){TestArray=new Array()TestArray=OrgSelshuf=new Array()x=0while(x<OrgSel.length){ran=Math.floor(TestArray.length*Math.random())shuf[x]=TestArray[ran]Fst=TestArray.slice(0,ran)Snd=TestArray.slice(ran+1)TestArray=Fst.concat(Snd)x++}ReArr(shuf)}function DesSel(){shuf=OrgSelshuf=shuf.sort()ReArr(shuf)}function AscSel(){shuf=OrgSelshuf=shuf.sort()shuf=shuf.reverse()ReArr(shuf)}function ReArr(arr){for(x=0;x<S.length;x++){S.options[x].value=arr[x]S.options[x].text=arr[x]}}</SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<FORM><SELECT size=7 name=SelectName> <OPTION value=Zero>Zero<OPTION   value=One>One<OPTION value=Two>Two<OPTION value=Three>Three<OPTION   value=Four>Four<OPTION value=Five>Five<OPTION value=Six>Six</OPTION></SELECT> <BR><HR><BR><INPUT onclick=ShfSel() type=button value=Shuffle> <INPUT onclick=DesSel() type=button value="Sort A-Z"> <INPUT onclick=AscSel() type=button value="Sort Z-A"> </FORM><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->