473,587 Members | 2,258 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 2236
> 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
8867
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
1666
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...
3
2903
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
5678
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...
26
17182
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
6105
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
1934
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
4220
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"...
0
1091
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
7915
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...
0
7843
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...
0
8205
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6619
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...
0
5392
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...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
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
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.