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.

Question:

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

Answer:

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;
    break;
  }
  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

Comments:

You are on page 3 of 3, other pages: 1 2 [3]
2013-07-09, 01:33:01
payday loans  
rating
2013-08-03, 15:18:10
payday loans  
rating
2013-10-10, 08:38:14
payday loans  
rating
pfnlbsw http://paydayloansusapwi.com/ payday loans kEfat http://paydayloansusaalh.com/ cash advance 4210 http://paydayloansnsa.com/ payday loans 6082 http://paydayloansusaccb.com/ payday loans :-O
2013-12-12, 22:26:51
payday loans  
rating
iajahsbx http://paydayloansu..cxc.co.uk/ payday loans 3251 http://2012paydayloans.net/ payday loans 8]]] http://paydayloansnsa.com/ payday loans 3211 http://paydayloansmsa.com/ payday loans %-[[[ http://paydayloansbsd.com/ payday loans uYEOR http://usapaydayloans24.com/ payday loans 3267 http://paydayloans24x7.com/ payday loans VTHqH
2014-01-14, 10:27:30
payday loans  
rating
ibhefp http://paydayloansusaplj.com/ payday loans UmXbNk http://paydayloansusaplh.com/ payday loans TqmLl http://paydayloansu..plj.co.uk/ payday loans YgUyY
2014-04-10, 16:37:39
free cialis samples  
rating
2014-04-15, 11:17:01
cialis free sample  
rating
2014-04-29, 10:37:33
cialis dosages tabs  
rating
2014-05-01, 19:20:37
payday loans  
rating
aqefaz http://paydayloansith.com/ payday loans dbytyw http://paydayloansitl.com/ unsecured loans online up to 1000 5304 http://paydayloansitq.com/ 100 day loans pdGCjT http://paydayloansitc.com/ instant loans MDwef
2014-05-19, 20:01:27
payday loans  
rating
fymlbsy http://paydayloansitt.com/ payday loans 6391 http://paydayloansito.com/ payday advance 0477 http://paydayloansitf.com/ cash advance online 7601 http://paydayloansitk.com/ pay day loans =-]
2014-06-13, 21:27:39
payday loans  
rating
dfsxkbr http://paydayloansusaprh.com/ payday loans YVtXG http://paydayloansusaplg.com/ payday loans >:-[ http://paydayloansitt.com/ payday loans YfjVH http://paydayloans24x7.com/ payday loans >:]] http://paydayloansnsa.com/ payday loans 2035 http://2012paydayloans.net/ payday loans laQRm http://paydayloansmsa.com/ payday loans YKrzb http://paydayloansitm.com/ payday loans 4914
2014-06-26, 16:08:32
quick money loans  
rating
zgjeni http://paydayloansqdn.com/ quick money loans 1068 http://paydayloansqdi.com/ money mutual 7456 http://paydayloansqdd.com/ 24 hour loans =-] http://paydayloansqdt.com/ 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: