View Full Version : Items in a select
Daniel Smith
11-01-2002, 10:05 PM
How do I access the property of an item in a select that defines its position in the list. I want to make a move up/move down function to order the list.
Thanks
chrismiceli
11-01-2002, 10:36 PM
<html>
<head>
<script language="javascript">
function moveUp() {
test = document.myform.box.selectedIndex + 1;
document.myform.box.selectedIndex = test;
}
</script>
</head>
<body>
<form name="myform">
<input type="button" value="move" onClick="moveUp()">
<select name="box">
<option>Blah</option>
<option>Blah1</option>
</form>
</body>
<html>
try that.
ConfusedOfLife
11-01-2002, 11:03 PM
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form>
<select name="oSel">
<option>G
<option>B
<option>D
<option>A
<option>O
</select>
</form>
<script>
function orderIt(what)
{
maxNum = document.getElementById(what).options.length;
oOpts = new Array();
// Initiating the array with the options.
for (count = 0; count < maxNum; count++)
oOpts[count] = document.getElementById(what).options[count].text;
// Sorting the array.
for (i=0; i<maxNum-1; i++)
for (j=i+1; j<maxNum; j++)
if ( oOpts[j] < oOpts[i] )
{
temp = oOpts[i];
oOpts[i] = oOpts[j];
oOpts[j] = temp;
}
// Changing the options and putting the ordered array as the options.
for (count=0; count<maxNum; count++)
document.getElementById(what).options[count].text = oOpts[count];
}
// Calling the function for a select called oSel
orderIt("oSel");
</script>
</body>
</html>
Daniel Smith
11-02-2002, 02:45 AM
That should help.
Thanks
:)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.