HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 17th, 2005, 05:22 AM
pdtn pdtn is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: South Australia
Posts: 41 pdtn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 47 sec
Reputation Power: 5
Send a message via MSN to pdtn
Ordering fields

Anyone know how to order a SELECT field in html in alphabetical order?
I'm too lazy to find the alphabetical positioning of the options, so i just want to sort them.

Reply With Quote
  #2  
Old January 17th, 2005, 08:28 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is online now
Moderator From Beyond
ASP Free God 46th Plane (27500 - 27999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,640 Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 374417 Folding Title: Super Ultimate Folder - Level 1Folding Points: 374417 Folding Title: Super Ultimate Folder - Level 1Folding Points: 374417 Folding Title: Super Ultimate Folder - Level 1Folding Points: 374417 Folding Title: Super Ultimate Folder - Level 1Folding Points: 374417 Folding Title: Super Ultimate Folder - Level 1Folding Points: 374417 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 3 h 4 m 37 sec
Reputation Power: 1902
no built in method, but you can use such code:
Code:
 <script type="text/javascript">
   function SortCombo(objCombo, ascending, byText)
   {
    for (var i=0; i<objCombo.options.length; i++)
    {
 	  var minMaxIndex=i;
 	  var minMaxValue=(byText)?objCombo.options[i].text:objCombo.options[i].value;
 	  for (var j=i+1; j<objCombo.options.length; j++)
 	  {
 		 var currentIndex=j;
 		 var currentValue=(byText)?objCombo.options[j].text:objCombo.options[j].value;
 		 if (((ascending)&&(currentValue < minMaxValue))||((!ascending)&&(currentValue > minMaxValue)))
 		 {
 			minMaxIndex = j;
 			minMaxValue = currentValue;
 		 }
 	  }
 	  if (minMaxIndex != i)
 		 ReplaceComboItems(objCombo, i, minMaxIndex);
    }
   }
   
   function ReplaceComboItems(objCombo, index1, index2)
   {
    var strTemp=objCombo.options[index1].text;
    objCombo.options[index1].text = objCombo.options[index2].text;
    objCombo.options[index2].text = strTemp;
    strTemp=objCombo.options[index1].value;
    objCombo.options[index1].value = objCombo.options[index2].value;
    objCombo.options[index2].value = strTemp;
   }
 </script>
 


to activate it, you have to tell it what combo to sort, whether to sort it ascending or not and whether to sort it by the text or value. for example, if you have form called "form1" with combo called "combo1" and you have to sort it by the text (what you actually see) in ascending order, have this in the body tag:
Code:
 <body onload="SortCombo(document.forms['form1'].elements['combo1'], true, true);">
 
Comments on this post
pdtn disagrees: It was useful

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Ordering fields


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT