Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 2nd, 2005, 07:50 AM
Registered User
 
Join Date: Aug 2005
Location: Bangalore, Karnataka, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to valentine
Default 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>



Similar Threads
Thread Thread Starter Forum Replies Last Post
Variey item in list box limit quatitiy and compare apple88 Classic ASP Databases 0 June 18th, 2007 02:25 AM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
Get the first item of a List hpox ASP.NET 2.0 Basics 1 February 16th, 2007 06:04 PM
Setting Text Box Focus sathish_reddy ASP.NET 1.0 and 1.1 Professional 1 November 22nd, 2006 02:26 AM
Want Combo Box first item if only 1 item markw707 Access 3 June 9th, 2004 04:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.