First off, I’m VERY new to javascript, so any help would be much appreciated.
I’m trying to move items in a list box (<select><option>) up and down using an up button and a down button. I have found some code that looks like it works (the items move up and down on the display), but the actual order stays the same. Does that make sense?
What I’m trying to do is allow a user to determine the order of the fields for a query. Although it looks like the field order has changed when user clicks the up or down button, the fields still display in the original order.
Here’s the code I’m using:
[CODE]function swapListItems(lObj,direction)
{
if (direction == ‘up’)
{
var temp;
if (!(lObj.selectedIndex==0))
{
temp = lObj.options[lObj.selectedIndex-1].text;
lObj.options[lObj.selectedIndex-1].text = lObj.options[lObj.selectedIndex].text;
lObj.options[lObj.selectedIndex].text = temp;
}
}
else
{
var temp;
if (!(lObj.selectedIndex==lObj.options.length-1))
{
temp = lObj.options[lObj.selectedIndex+1].text;
lObj.options[lObj.selectedIndex+1].text = lObj.options[lObj.selectedIndex].text;
lObj.options[lObj.selectedIndex].text = temp;
}
}
}
//Function to Move List Items to Up
function moveUp()
{
var listObject = eval(document.tableEdit.selectedOptions);
if(!(listObject.selectedIndex==-1))
{
var selected = listObject.selectedIndex;
swapListItems(listObject,’up’);
listObject.selectedIndex = selected – 1;
}
else
{
alert(‘Please select an item to move up’);
}
}
//Function to Move List Items to Down
function moveDown()
{
var listObject = eval(document.tableEdit.selectedOptions);
if(!(listObject.selectedIndex==-1))
{
var selected = listObject.selectedIndex;
swapListItems(listObject,’down’);
listObject.selectedIndex = selected + 1;
}
else
{
alert(‘Please select an item to move down’);
}
}
Can anyone help??