I have a pull down box populated by a case statement. I would like to sort that list alphanumerically "on the fly" if that is possible. Is there some kind of "sort" script that will do this?
Thanks
-pc
Solved! Go to Solution.
Views
Replies
Total Likes
Ok,
in this case you can use a script in the enter:Event of the drop down box which will extract all current records, sort them and write them back into the box.
var ListItems = new Array();
for (var i=0; i < this.length; i++)
{
var nItem = this.getSaveItem(i);
ListItems.splice(i, i, nItem);
ListItems.sort();
}
this.clearItems();
for (var i=0; i < ListItems.length; i++)
{
this.addItem(ListItems[i]);
}
Hope this helps
Views
Replies
Total Likes
Hi,
generally "yes". You can use the sort() function of javascript.
How do you populate your drop down box?
Views
Replies
Total Likes
Using a case statement like - but I have several of these tied to on dropdownlist......
case
"NW1 - WA":
for (var i=1; i<=7; i++)
{
var DD = xfa.resolveNode("form1.Page1.Osr"+i);
DD.rawValue
= null;
DD.clearItems();
DD.addItem("Gary Gray");
DD.addItem("Mike Davis");
DD.addItem("James Schiessl");
DD.addItem("Joel Schalo");
DD.addItem("Todd Olson");
DD.addItem("Ken Canady");
DD.addItem("Tony Adams");
DD.addItem("April Gray");
DD.addItem("Melanie Smith");
DD.addItem("Elisa Tamez");
DD.addItem("James Moore");
DD.addItem("Chrissy Cope");
DD.addItem("Gregg Petet");
DD.addItem("Chris Danhof");
DD.addItem("Chuck Baker");
DD.addItem("Michelle Russell");
DD.addItem("Mingie Holland");
}
break;
Views
Replies
Total Likes
Ok,
in this case you can use a script in the enter:Event of the drop down box which will extract all current records, sort them and write them back into the box.
var ListItems = new Array();
for (var i=0; i < this.length; i++)
{
var nItem = this.getSaveItem(i);
ListItems.splice(i, i, nItem);
ListItems.sort();
}
this.clearItems();
for (var i=0; i < ListItems.length; i++)
{
this.addItem(ListItems[i]);
}
Hope this helps
Views
Replies
Total Likes
So where would I actually drop in that code?
I have my "Region" pull down that populated the "District" pulldown that populates the "Location" pulldown that populates the "Account Lead" pulldown.
The accound lead are the items I want to sort alphabetically. I added the code both to the Location and Account Lead and it didn't seem to sort.
Dumb question - do I need to make changes to the script you posted to make it work with my specific form?
Thanks,
-pc
Views
Replies
Total Likes
Added a -1 to the length statement
for
(var i=0; i < this.length-1; i++)
and it works!
Thanks,
Patrick
Views
Replies
Total Likes
Actually it works exactly as you posted....when you add the -1 it removes a name from the list each time you open it which is kind of interesting but probably not usefull....Anyway Thanks!
Views
Replies
Total Likes
Views
Likes
Replies