473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

(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 2704
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

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

Similar topics

2
by: Xerxes | last post by:
Hi, how can I pass the returned value from Javascript to PHP? I have: ------------------------------------------------------------------------ ------ if ( x>y) {
5
by: Jim Bond | last post by:
Hello, I have found myself in the position of having to manage & "hack" a web site built by someone else. I am trying to make a modification to the javascript code and have been unable to get...
9
by: Harry | last post by:
I am accumulating over 80 pages per day into an archive that I will need to be able to present sequentially to viewers. Using html to viewing a page, then click on back to return to my archive...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: simon.cigoj | last post by:
I have an javascript made menu and some forms with the dropdown element. When the menu opens and scrolls down the drop down is displeyed over the menu and obscures the menu choices. I have this...
0
by: Mythran | last post by:
I wrote an editor for a web control that allows it to list all controls on a page in a drop down box in the property grid. In the EditValue method, I have the following (not all the code, but most...
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
2
by: juliek | last post by:
I hope someone can help me. When a user selects a new item from a drop down list on an ASP.NET form, I'd like a javascript function to execute. How can I do this? I'm running the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.