DelphiFAQ Home Search:

How to insert a string into a sorted SELECT listbox


comments43 comments. Current rating: 3 stars (34 votes). Leave comments and/ or rate it.


I have a sorted listbox and want to insert a new string without a complete resort.


Use the javascript function shown below - pass the string that you want to insert as an argument. The name of the SELECT listbox is hard-coded in the script as 'mylist'.

Call it like this:
insertSortedLb('New Name')

The case is case sensitive and sorts alphabetically.
That means if you have numbers in the listbox, and these numbers include
10, 2, 300
then it will sort these numbers as
10, 2, 300
NOT as
2, 10, 300

function insertSortedLb(sVal) {
var lb = document.getElementById('mylist');

oOption = document.createElement("OPTION");
oOption.text = '';
oOption.value = '';
oOption.selected = false;
lb.options[lb.length] = oOption;

for(i=lb.length-1; i>0; i--)  {
  if (lb.options[i-1].text < sVal) {
    oOption = document.createElement("OPTION");
    oOption.text = sVal;
    oOption.value = sVal;
    oOption.selected = false;
    lb.options[i] = oOption;
  else {
    lb.options[i].text = lb.options[i-1].text;
    lb.options[i].value = lb.options[i-1].value;
} // for
} // end of insertSortedLb()

Content-type: text/html


You are on page 3 of 3, other pages: 1 2 [3]
2013-07-09, 01:33:01
payday loans  
2013-08-03, 15:18:10
payday loans  
2013-10-10, 08:38:14
payday loans  
pfnlbsw payday loans kEfat cash advance 4210 payday loans 6082 payday loans :-O
2013-12-12, 22:26:51
payday loans  
iajahsbx payday loans 3251 payday loans 8]]] payday loans 3211 payday loans %-[[[ payday loans uYEOR payday loans 3267 payday loans VTHqH
2014-01-14, 10:27:30
payday loans  
ibhefp payday loans UmXbNk payday loans TqmLl payday loans YgUyY
2014-04-10, 16:37:39
free cialis samples  
2014-04-15, 11:17:01
cialis free sample  
2014-04-29, 10:37:33
cialis dosages tabs  
2014-05-01, 19:20:37
payday loans  
aqefaz payday loans dbytyw unsecured loans online up to 1000 5304 100 day loans pdGCjT instant loans MDwef
2014-05-19, 20:01:27
payday loans  
fymlbsy payday loans 6391 payday advance 0477 cash advance online 7601 pay day loans =-]
2014-06-13, 21:27:39
payday loans  
dfsxkbr payday loans YVtXG payday loans >:-[ payday loans YfjVH payday loans >:]] payday loans 2035 payday loans laQRm payday loans YKrzb payday loans 4914
2014-06-26, 16:08:32
quick money loans  
zgjeni quick money loans 1068 money mutual 7456 24 hour loans =-] 100 day loan 9804
2014-12-26, 05:25:36
anonymous from Untersiemau, Germany  
Of course they canThey edtenxed you credit and you didn't repay them according to the contract (it's like 5 or 6 pages that you have to sign to take out these loans, lots of small print that informs you they can report you if you do not pay) Depends on what the class action suit is about. The thing is, by the time the class action suit is ironed out, it would either be off your report (aged off) or you will be sued by them or the collection agency they sell your debt to, so it won't matter.
You are on page 3 of 3, other pages: 1 2 [3]



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: