Select List Text Moves Up and Down

[Total: 0    Average: 0/5]

This code moves an item up or down.

Head Code:

<script>
function up(obj)
{
  var currernt;
  var reverse;
  if(obj.options[obj.options.selectedIndex].index > 0)
  {
    current = obj.options[obj.options.selectedIndex].text;
    reverse = obj.options[obj.options[obj.options.selectedIndex].index-1].text;
    obj.options[obj.options.selectedIndex].text = reverse;
    obj.options[obj.options[obj.options.selectedIndex].index-1].text = current;
    self.focus();
    obj.options.selectedIndex--;
  }
}

function down(obj)
{
  var currernt;
  var next;
  if(obj.options[obj.options.selectedIndex].index != obj.length-1)
  {
    current = obj.options[obj.options.selectedIndex].text;
    next = obj.options[obj.options[obj.options.selectedIndex].index+1].text;
    obj.options[obj.options.selectedIndex].text =  next;
    obj.options[obj.options[obj.options.selectedIndex].index+1].text = current;
    self.focus();
    obj.options.selectedIndex++;
  }
}
</script>

Body Code:

<FORM METHOD=POST ACTION="">
<select name="s1" MULTIPLE size=6>
<option>ONE
<option>TWO
<option>THREE
<option>FOUR
<option>SAQIB
<option>KHAN
</select> <input type=button value="UP" onClick="up(s1)"><input
type=button value="Down" onClick="down(s1)">
</FORM>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *