Categories:

Home / Free JavaScripts / Forms / Here

Cut & Paste PickList II (aka Menu Swapper)

Credit: Phil Webb

Description: This JavaScript code moves form elements from one select box to the other. It allows for multiple items to be moved at once, and all items are sorted alphabetically as they are moved. The items are sorted by their description, not their value, which is helpful when pulling items from a database which have random IDs associated with them.

Note: The function move merely moves the items back and forth. This function alone will not select any of the items to be sent along with the post. In other words nothing will be sent in the form when you submit it unless some items are selected (highlighted) or additional JavaScript code it used. In this page I have added the function selectAll which loops through the righthand box and selects all the items before the form is submitted. This is much more intuitive for the user. The function selectAll is called in the onClick event of the submit button. -Above description by the author.

Example:

Directions

Step 1: Insert the below script into the <HEAD> section of your page:

Step 2: Then, add the below example form into your page:

If you intend to use the script in a PHP program be aware of the way php handles multiple selects. This page from the php manual explains it.


Copyright © 1997-2014 JavaScript Kit. NO PART may be reproduced without author's permission.