473,666 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select boxes and ordering

I have 10 select boxes, they have select values of 1 to 10 (one of
each value).

I'd like to be able to change one of the select boxes and have the
rest reorder themselves accordingly.

I thought this would be simple, as the values of the other select
boxes are either incremented up (if going from a smaller value to a
larger) or incremented down over the range of the old value to (and
including) the new value.

Then it occured to me that when you do an onchange that you only
know the new value, not the old.

Anyone have a simple solution to this? I think I must just be
missing something.

Cheers,
Jeff
(at the girlfriends, sorry about the Google post)
Jul 20 '05 #1
1 2240
> I have 10 select boxes, they have select values of 1 to 10 (one of
each value).

I'd like to be able to change one of the select boxes and have the
rest reorder themselves accordingly.

I thought this would be simple, as the values of the other select
boxes are either incremented up (if going from a smaller value to a
larger) or incremented down over the range of the old value to (and
including) the new value.

Then it occured to me that when you do an onchange that you only
know the new value, not the old.
Here's what I came up with:

var orderArray=new Array(); // hash to store last values.
function setOrderArray() { // call this function on initialize
var form=document.f orms[0];
for (var i=0; i<form.length;i ++){
var el=form[i];
if(el.type=='se lect-one'){ // assumes only rolldowns are for "ordering"
orderArray[el.name]=(el.selectedIn dex +1);
}
}
}

function setOrder(obj){ // call this onchange="setOr der(this)" in the //
rolldowns
var to=obj.selected Index+1;
var from=orderArray[obj.name];
for (var elname in orderArray){
var n=orderArray[elname];
if((from > to)&&(n >= to)&&(n < from)){
document.forms[0][elname].selectedIndex= document.forms[0][elname].selectedIndex+ 1;
}
if((from < to)&&(n <= to)&&(n > from)){
document.forms[0][elname].selectedIndex= document.forms[0][elname].selectedIndex-1;
}
}
setOrderArray() ;
}

A bit funky, but works...

Cheers,
Jeff

Anyone have a simple solution to this? I think I must just be
missing something.

Cheers,
Jeff
(at the girlfriends, sorry about the Google post)

Jul 20 '05 #2

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

Similar topics

12
8869
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
4
1668
by: adam | last post by:
hello I have strange problem. I write to MySQL data to table with one column of varchar(8000). I write 750000 bytes, so it get 93 records of 8000 bytes and the last - 6000bytes. but what is strange - when I check length of this records: select len(column_name) from table_name this last record ( which is 6000bytes length ) isn't on 94 position, but ...
3
2905
by: Cindy | last post by:
OK, I have the following table: create table citations_by_level ( aid smallint, wid smallint, v_level varchar(50), w_level varchar(50), x_level varchar(50), y_level varchar(50),
1
5747
by: Matt Roberts | last post by:
Please accept my apologies if this is answered elsewhere in the archives or docs but I have searched without luck. I've always assumed that default ordering of selects are based on a first in first out principle and that this remains true at the row level despite edits to columns. However I'm dealing with a case where this doesn't seem to hold true. The ordering has changed over time. Its difficult for me to gauge whether the data has...
26
17190
by: GreatAlterEgo | last post by:
Hi, This is my query which is embedded in a COBOL program. EXEC SQL SELECT DATE, AGE, DURATION, AMT INTO :LDATE, :L.AGE, :L.DURATION, :L.AMT FROM TAB1 WHERE CODE = :KEY.CODE AND SET = :KEY.SET AND DATE <= :KEY.DATE
17
6128
by: glenn.robinson | last post by:
Hello, DB2 for iSeries - V5R2 I have a table with a non-unique index, column name SEDOL. I need to extract the 2nd row from each set of SEDOL rows in the table. If only one SEDOL row exists then select that one row. As an example:
4
1935
by: Jean-Claude | last post by:
Hi, which is the faster query ? (of course, in my case the real queries are more complex) 1/ select * from file1 a join file2 b on b.key=a.key where b.data=123 and b.name='TEST'
48
4237
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) * -1 Set oConn=Server.CreateObject("ADODB.Connection") Set oRS=Server.CreateObject("ADODB.recordset") oConn.Provider="Microsoft.Jet.OLEDB.4.0" oConn.Open Server.MapPath("temp.mdb")
0
1092
by: twinklyblue | last post by:
Hi The Scripts team, I would like to ask how oracle handles ordering of japanese characters? I have used order by in my select statement but is not sure if it displays the correct ordering. Thank you in advance..
0
8443
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7385
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.