473,401 Members | 2,139 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,401 software developers and data experts.

select options property

I understand that the options property of a select element is an array
of the options displayed by the select element. If that's so, then
why can't I sort the array? Rather, I *want* to sort the options =
how do I do it?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #1
6 2011
Christopher Benson-Manica wrote:
I understand that the options property of a select element is an array
of the options displayed by the select element. If that's so, then
why can't I sort the array? Rather, I *want* to sort the options =
how do I do it?


I've not sorted anything in js yet but... I'm wondering if you are
sorting by the option value as opposed to the text value... Can you
provide some code, or a url for someone here to look at?

randelld
Jul 23 '05 #2
"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote:
I understand that the options property of a select element is an array
of the options displayed by the select element. If that's so, then
why can't I sort the array? Rather, I *want* to sort the options =
how do I do it?


I have selectbox functions available, and one of them is a sortSelect()
method. It might do what you want, or get you started in the right
direction:
http://www.mattkruse.com/javascript/selectbox/

--
Matt Kruse
Javascript Toolbox: http://www.mattkruse.com/javascript/
Jul 23 '05 #3
Matt Kruse <ne********@mattkruse.com> spoke thus:
I have selectbox functions available, and one of them is a sortSelect()
method. It might do what you want, or get you started in the right
direction:
http://www.mattkruse.com/javascript/selectbox/


Is it just me, or was there a newline deficiency when you wrote the
scripts? :) Anyway, from what I can see it looks like you're doing
the same thing I am, which is to use an array to actually sort the
data and then repopulate the select element. What I really wanted to
know is why the options property returns something that can't be
sorted with sort()...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #4
"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote:
Is it just me, or was there a newline deficiency when you wrote the
scripts? :)
Nah, the page is just linked to the 'compact' version of the source. If you
click on the 'Source' link at the top, you can get it in its full commented
form to read and understand. The compact version is for 'production' use
where you might want to reduce file size :)
What I really wanted to
know is why the options property returns something that can't be
sorted with sort()...


Options are very picky, I've found. In most browsers that I've tested, you
can't manipulate or move around the option objects. In fact, caching
Option() objects in scripts and then adding or removing them from lists
causes odd behavior. Based on my testing with multiple browsers, the best
way to manipulate options is to always create a new Option() object and
replace an option or add it to the list. Doing anything else causes very
unpredictable results.

--
Matt Kruse
Javascript Toolbox: http://www.mattkruse.com/javascript/
Jul 23 '05 #5
On Wed, 14 Apr 2004 20:50:43 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.cyberspace.org> wrote:
I understand that the options property of a select element is an array
of the options displayed by the select element. If that's so, then
why can't I sort the array? Rather, I *want* to sort the options =
how do I do it?


HTMLSelectElement.options is not an array, but a collection. Collections
have length properties and they can be subscripted like arrays, but they
do not have the methods and other properties that arrays do.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #6
Michael Winter <M.******@blueyonder.co.invalid> spoke thus:
HTMLSelectElement.options is not an array, but a collection. Collections
have length properties and they can be subscripted like arrays, but they
do not have the methods and other properties that arrays do.


Ah, thank you - that's what I was looking for.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Damgaard | last post by:
Hi, I need to have two <SELECT> boxes: "brand" and "model". The user should first select brand. Then the other select box should contain the options dependend of what user chose in "brand". I...
3
by: Dennis M. Marks | last post by:
I have a problem with the following code. It generates a <FORM><SELECT><OPTION> list. There is no problem in the generating. The problem is in the execution as follows. It works fine in Mac IE...
0
by: Francis Parsons | last post by:
Hi! I'm doubtful there's a workaround for this problem, but it's worth a shot. I'm using IE's (css) "zoom" property to zoom the body of a document (in conjunction with persistance so the...
5
by: callmebill | last post by:
I'm relatively new to javascript, and I'm trying to decide whether the following (and if so, clues on how to do it): I'd like to create two HTML multiple-select boxes. The first would be a list...
2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
2
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
2
by: Rob Long | last post by:
Hi I have an HTML select element in my page and it's multiple property is disabled (one item at a time mode) but I still want to transfer all the items in the select to the server when the form...
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...
11
by: Richard Maher | last post by:
Hi, I have read many of the copius entries on the subject of IE performance (or the lack thereof) when populating Select Lists. I don't mind the insert performance so much, (I get 100x120byte...
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...
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.