469,344 Members | 5,424 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

(JavaScript) How Can I do drop down list sorting?

Hi,

I have drop down list which is populating form the xml by using AJAX.
After getting the text in that opetion I want to do sorting in java script.
How can I do?
please help me.

Regards,
Bhavani
Sep 11 '07 #1
4 2597
gits
5,390 Expert Mod 4TB
hi ...

the best way would be to put the optionvalues and texts into an js-array ... sort this now ... and after this is sorted ... populate your menulist with the sorted values

kind regards
Sep 11 '07 #2
hi ...

the best way would be to put the optionvalues and texts into an js-array ... sort this now ... and after this is sorted ... populate your menulist with the sorted values

kind regards
Hi gits,

i have the xml like
Expand|Select|Wrap|Line Numbers
  1. <LETTER file="ATM_Letter.doc" text="ATM Letter"/>
  2. <LETTER file="Collateral_Correction_Letter_and_CCS.doc" text="Collateral Correction Letter and CCS"/>
  3. .....................
  4. ..............
......................

I am populating the xml values in menu options like following.
var menuOption = new Option(text , file, false, false);

How can I convert this Option to Array?
Sep 11 '07 #3
pbmods
5,821 Expert 4TB
Heya, Bhavanirayala.

Please use CODE tags when posting source code:

[CODE=xml]
XML code goes here.
[/CODE]

This is not the first time you've been asked.
Sep 11 '07 #4
gits
5,390 Expert Mod 4TB
hi ...

you don't have to convert this ... or whatever. simply put them into a list that is indexed with the key you want to sort:

Expand|Select|Wrap|Line Numbers
  1. var list = {};
  2. var sort_list = [];
  3.  
  4. // everytime you have retrieved a new option
  5. // you do:
  6. list[text] = menuOption;
  7.  
  8. // where menuOption is the ref to the new Option() you already have
  9. // AND !!!
  10. sort_list.push(text);
  11.  
now you may simply sort the sort_list with the array sort() method.
after that ... you loop through the sorted list, and get the corresponding option from our 'option'-list:

Expand|Select|Wrap|Line Numbers
  1. for (var i = 0; i < sort_list.lenght; i++) {
  2.     var item = sort_list[i];
  3.     var option_to_add = list[item];
  4.     // add the option here to your menulist :)
  5. }
  6.  
kind regards
Sep 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Xerxes | last post: by
5 posts views Thread by Jim Bond | last post: by
4 posts views Thread by simon.cigoj | last post: by
reply views Thread by Mythran | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.