Move and Change order from multiple pairs (multiselect to single select)
Move and Change order from multiple pairs (multiselect to single select).
I think I originally got from:
http://www.mredkj.com/tutorials/tutorial_mixed2b.html
function addOption(theSel, theText, theValue) {
var newOpt = new Option(theText, theValue);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;
}
function moveUpDown(obj1, obj2, list, to) {
var index = list.selectedIndex;
var total = list.options.length-1;
if (index == -1) return false;
if (to == +1 && index == total) return false;
if (to == -1 && index == 0) return false;
var items = new Array;
var values = new Array;
for (i = total; i >= 0; i--) {
items[i] = list.options[i].text;
values[i] = list.options[i].value;
}
var tempFromItem = items[index];
var tempFromValue = values[index];
var tempToItem = items[index + to];
var tempToValue = values[index + to];
items[index] = tempToItem;
values[index] = tempToValue;
items[index + to] = tempFromItem;
values[index + to] = tempFromValue;
for (i = total; i >= 0; i--) {
if (i == index + to) {
list.options[i] = new Option(items[i], values[i],0 ,1);
} else {
list.options[i] = new Option(items[i], values[i]);
}
}
var stroptions = "";
var stroptionsvalue = "";
for (i = 0; i <= total; i++) {
if (i!=0) stroptions += ",";
stroptions += list.options[i].text;
if (i!=0) stroptionsvalue += ",";
stroptionsvalue += list.options[i].value;
}
obj1.value = stroptions;
obj2.value = stroptionsvalue;
list.focus();
}
function deleteOption(theSel, theIndex) {
var selLength = theSel.length;
if(selLength>0) {
theSel.options[theIndex] = null;
}
}
function moveOptions(obj1, obj2, ListFrom, ListTo, SelFrom, SelTo) {
var theListFrom = document.getElementById(ListFrom);
var theListTo = document.getElementById(ListTo);
var theSelFrom = document.getElementById(SelFrom);
var theSelTo = document.getElementById(SelTo);
var selLength = theSelFrom.length;
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.