dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Web
Expertise: Beginner
Mar 12, 2002

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Swap List Items in a Given Direction

 
<script language="javascript">
//Author : Sudhakar SVS
//Function to Swap the List Items in given direction
//Date   : 11-Apr-2001
//Parameters :	lObj - ListBox Object
//direction - direction to move should be either 'up' _
or 'down'


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.myForm.mylist);
				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.myForm.mylist);
				if _
(!(listObject.selectedIndex==-1))
				{
				var selected = _
listObject.selectedIndex;
				_
swapListItems(listObject,'down');
				listObject.selectedIndex _
= selected + 1;
				}
				else
				{
					_
alert('Please select an item to move down');
				}

			}
		</script>


//Implementation of JS Functions
//------------------------------

//To Move up
<img name="moveup" id="moveup" src="moveup.gif"
onclick="Javascript:moveUp()" border="0">

//To Move down
<img name="movedown" id="movedown" src="movedown.gif"
onclick="Javascript:moveDown()" border="0">
Sudhakar Sadasivuni
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date