/    Sign up×
Community /Pin to ProfileBookmark

Menu Swapper Pick List

Hi,

I am using the menu swapper javascript downloaded from [url]http://www.javascriptkit.com/script/script2/picklist2.shtml[/url] and I am loading a series of events as the available select items from a mysql table. I have specified the sort order in the original page load to be by event date even though this is not used as part of the displayed event description text. When I select one item the available list gets re-sorted to alphabetic using description name.

I was hoping if someone can help me in being able to retain the original sort order after that first selection. In the javascript code below the “arrFbox.sort();” line is where the sort happens and if I remove this line then that will stop any re-sorting, but leaving it in re-sorts alphabetic by description. Can anyone offer me some suggestions here please?

Many Thanks, Paulb

Menu Swapper Code:

function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for(i=0; i<tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length
for(i=0; i<fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if(fbox.options[i].selected && fbox.options[i].value != “”) {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
} else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
}
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c=0; c<arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c=0; c<arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}
}
function selectAll(box) {
if (box.length == 0) {
alert(“Please select at least one show.”);
box.focus();
return (false);
}
for(var i=0; i<box.length; i++) {
box.options[i].selected = true;
}
}

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @paulb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...