473,396 Members | 1,683 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,396 software developers and data experts.

Order the options of a select list

97 64KB
I have a php for loop that generates a select list, but I can't figure out how to order the options of the list the way I want.

This is the php:

Expand|Select|Wrap|Line Numbers
  1. static function tp_widget_do($args) {
  2.   echo '<span class="' . NO_TRANSLATE_CLASS . '">';
  3.  
  4.   echo '<select name="lang" onchange="document.location.href=this.options[this.selectedIndex].value;">'; 
  5.  
  6.   foreach ($args as $langrecord) {
  7.     $is_selected = $langrecord['active'] ? " selected=\"selected\"" : "";
  8.     echo "<option value=\"{$langrecord['url']}\"{$is_selected}>{$langrecord['langorig']}</option>";
  9.   }
  10.   echo "</select><br/>";
  11.  
  12.   echo "</span>";
  13. }
  14.  
I was thinking of using either 'usort' or maybe even some javascript to sort the list of options in the select list. What I really need is to sort them in descending order.
Oct 14 '16 #1
1 1044
Dormilich
8,658 Expert Mod 8TB
that's correct. you would use usort() for that.
Oct 17 '16 #2

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

Similar topics

1
by: Adrian | last post by:
This script works well for searching thru a SELECT list but doesnt work so well with the MULTIPLE option. I need to modify it to work for a SELECT MULTIPLE but I have no idea where to begin, any...
4
by: Pasquale | last post by:
Hello, I wondering if there is a way to dynamically update a select list with javascript from a database query without having to reload the page to update the list?
8
by: asd | last post by:
I need to find the value/index of the previously selected item of a select list. That is, when the user selects an item from the list and a certain condition elsewhere in the form is not met, I...
4
by: bobsawyer | last post by:
I've been building a series of SELECT lists that are populated dynamically using HTTPRequest. Things are going pretty well, and I've got the whole thing working flawlessly in Mozilla/Firebird....
1
by: mike | last post by:
I have a select list defined like: <select name="cri2" multiple style="height:220px; width:300px;" onClick="show_content(this);"> </select> I add content to it dynamically using a function...
1
by: jojowebdev | last post by:
I have been TRYING for a few days to get a *working* search of a select list (about 800 options in list). I have not found one that works for IE6. Here is what I *last* tried. I would appreciate...
4
by: Ian Richardson | last post by:
Hi, The function I've put together below is a rough idea to extend a SELECT list, starting from: <body> <form name="bambam"> <select id="fred"> <option value="1">1</option> <option...
4
by: rn5a | last post by:
A Form has 2 select lists. The 1st one whose size is 5 (meaning 5 options are shown at any given time) allows multiple selection whereas the 2nd one allows only 1 option to be selected at a time. ...
3
by: Italio Novuas | last post by:
Hi all, let me begin by saying that I *ALMOST* have this complete! What I'm trying to do is make it so my text area shows the innerHTML of any select item with the same value. For example, if I...
1
by: Max58kl | last post by:
I have a select list that allows me to filter the results of a database search. The user chooses from a dropdown menu then clicks submit. The target page shows only the records containing what...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.