list box item moved up and down with focus
This code is used for the functionality of list box.
In this list box item can be selected and moved up and down without "loosing focus",and its applicable to Multiple selction also.
-----------------------------cut this code and paste----------------
<script type="text/javascript">
function BumpUp(abox)
{
for(var i = 0; i < abox.options.length; i++)
{
if(abox.options[i].value == "")
{
for(var j = i; j < abox.options.length - 1; j++)
{
abox.options[j].value = abox.options[j + 1].value;
abox.options[j].text = abox.options[j + 1].text;
}
var ln = i;
break;
}
}
if(ln < abox.options.length)
{
abox.options.length -= 1;
BumpUp(abox);
}
}
function Moveup(dbox)
{
//alert("moving up");
for(var i = 0; i < dbox.options.length; i++)
{
if (dbox.options[i].selected && dbox.options[i] != "" && dbox.options[i] != dbox.options[0])
{
var selected = dbox.options[i].selected;
var tmpval = dbox.options[i].value;
var tmpval2 = dbox.options[i].text;
dbox.options[i].value = dbox.options[i - 1].value;
dbox.options[i].text = dbox.options[i - 1].text
dbox.options[i-1].value = tmpval;
dbox.options[i-1].text = tmpval2;
if(selected)
{
dbox.options[i-1].selected = true;
}
else
{
dbox.options[i-1].selected = false;
}
dbox.options[i].selected = false;
}
}
}
function Movedown(ebox)
{
if(ebox != null)
{
var size =ebox.options.length;
if(size > 0)
{
for(i=(size-1); i>=0; i--)
{
var obj1 = ebox.options[i];
if((obj1 != null) && (obj1.selected==true))
if((i+1) < size)
{
// Swap the elements.
var tempVal = ebox[i].value;
var tempTxt = ebox[i].text;
ebox[i].value = ebox[i+1].value;
ebox[i].text =ebox[i+1].text;
ebox[i+1].value = tempVal;
ebox[i+1].text = tempTxt;
ebox[i].selected = false;
ebox[i+1].selected = true;
}
}
}
}
}
</script>
|