• Home
  • Amoeba
  • ASK
  • Community
  • Source Codes
  • Contact Us
Blue Orange Green Pink Purple

HTML Form – Moving options from one SELECT to another

Posted in CSS & XHTML, Javascript & Libraries. on Monday, February 15th, 2010 by Aneeska
Feb 15

This article basically talks about two things.

1) A Javascript code to move options from one multiple select box to another in a form.

Move options from one SELECT box to another:

There are two multiple SELECT boxes and one has got some OPTIONS in it. User can select one or more options from one and click on the Move button to transfer the selected options in to the other one. Similarly, the selected options from the second SELECT box can be moved back to the first one.

Here is the HTML Code:

<form action="" method="post">
  <table width="250" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="100"><select name="SourceSelect[]" id="sourceSelect" size="5" multiple ondblclick="moveData(); return false;">
          <option value="1">America</option>
          <option value="2">Canada</option>
          <option value="3">China</option>
          <option value="4">England</option>
        </select></td>
      <td width="100" align="center" valign="middle"><input type="submit" name="forward" id="button" value=">>>>" onclick="moveData(); return false;"/>
        <input type="submit" name="back" id="button" value="<<<<" onclick="moveData('back'); return false;"/></td>
      <td align="left"><select name="DestinationSelect[]" id="destinationSelect" size="5" multiple="multiple" ondblclick="moveData('back'); return false;">
        </select></td>
    </tr>
  </table>
</form>

And here is the Javascript code:

<script type="text/javascript" language="javascript1.2">
function moveData(dir) {
	var sF = document.getElementById(((dir == "back")?"destinationSelect":"sourceSelect"));
	var dF = document.getElementById(((dir == "back")?"sourceSelect":"destinationSelect"));
	if(sF.length == 0 || sF.selectedIndex == -1) return;
	while (sF.selectedIndex != -1) {
		dF.options[dF.length] = new Option(sF.options[sF.selectedIndex].text, sF.options[sF.selectedIndex].value);
		sF.options[sF.selectedIndex] = null;
	}
}
</script>

The above code also allows you to double click on a select option to move it to the other.


ASK a Question!

Bookmark and Share

Leave a Reply

CAPTCHA Image CAPTCHA Audio
Refresh Image
  • Search a Topic


  • Got a Question?
      ASK and get a Solution! ASK
  • Categories
    • CakePHP
    • Computers
    • CSS & XHTML
    • Enterprise Web
    • Flash & Action Script
    • Flex
    • Javascript & Libraries
    • Perl Programming
    • PHP/MySQL
    • Programming Techniques
    • Regular Expression
    • Social Media
  • Recent Visitors
  • Recent Articles
    • How to Protect your SWF (AS2 or AS3). Prevent SWF Decompile using SWF Protector
    • PHP – Search in an Array for Values Matching a Pattern – Regex, Wildcard
    • PHP – How to Get Browser Properties and Capabilities – get_browser()
    • CakePHP – Search for records between two dates inclusively
    • Notebook/Laptop hangs frequently/random (on Low Battery when AC power is connected)
    • Swap Values Without Temp or A Third Variable in PHP
    • CakePHP – Auth Login Redirect Problem with Plugins
    • Convert PHP array to Javascript array
    • CakePHP – Accessing a model in AppController or in any Controllers
    • Save Images from Flash – Actionscript 3, Filereference.save, JPGEncoder
  • Archives
    • September 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
  • Tags
      vertically center horizontally align dead center div amoeba ask credit card workbench decryption solutions kiosk questions horizontal center align vertical center align css trick solution css encryption as2 flash regex as3 Regular Expression action script mysql array CakePHP php

  • Donate

      If you find this site helpful, please donate to Amoeba Solution Kiosk. We will be using the money received for conducting technology awareness camps and seminars for school and college students in rural areas of Kerala, India.

  • Links
    • Amoeba Solutions
    • Blog Catalog
  • Home
  • Amoeba
  • ASK
  • Community
  • Source Codes
  • Contact Us

© Copyright Amoeba Solution Kiosk. All rights reserved.
An Amoeba Concept!

Back to Top