/    Sign up×
Community /Pin to ProfileBookmark

Function Problem revisited…

Thx for previous help to get this thing working. Just learned that sorting is now a requirement. I’ve tried several variations of code using sort() but can’t seem to get it to work. Not sure if it’s even possible. If anyone can help it’d be much appreciated.

All I need the below function to do is sort each of 2 lists alphabetically when items are moved from one side to the other. If you cut/paste the code below you should instantly see what I mean by this.

Anyway, thanks in advance!

<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
function moveOver(fromList,toList,limit)
{
var undefined;
var boxLength = toList.length;
var selectedItem = fromList.selectedIndex;
var selectedText = fromList.options[selectedItem].text;
var selectedValue = fromList.options[selectedItem].value;

var i;
var isNew = true;;

if ( ((limit != undefined) && (boxLength<limit)) || limit == undefined ) {

if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = toList.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}

if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
toList.options[boxLength] = newoption;
}
fromList.options[selectedItem] = null;
fromList.selectedIndex=-1;

} else {
alert(“This is a limit of ” + limit + ” choices for this list.”);
}
}
</SCRIPT>

<form>
All Available Users:
<select multiple name=”userID” style=”width:275;” size=”6″ onchange=”moveOver(this,this.form.list);”>
<option>Option1</option>
<option>Option2</option>
<option>Option3</option>
<option>Option4</option>
</select>

Users in this Group:
<select multiple name=”list” style=”width:275;” size=”6″ onchange=”moveOver(this,this.form.userID);”>
<option>Option6</option>
<option>Option7</option>
<option>Option8</option>
<option>Option9</option>
</select>
</form>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangMay 14.2004 — Easier to have the options saved in an array, then sort array and write the contents to the select box.
×

Success!

Help @Nanwedar 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.18,
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,
)...