473,378 Members | 1,134 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,378 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 2703
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.