How to add/remove items from one list box  to another in the same form with php??

Posted on 2006-04-16
Last Modified: 2013-12-13
I have two list boxes on the same page. One is populated with items from a database table. I want to be able to select an item at a time, choose the quantity from a dropdown list, then click on a button 'Add' and transfer the selected item from list box 1 to list box 2 with the corresponding quantity. I want to be able to do this multiple times. Also, when the item is added from list box 1 to list box 2, it should disappear from list box 1 to prevent the user from choosing the same item more than once. Similarly, the user should be able to select an item from list box 2, click on button 'Remove' and move the item back to list box 1 while it disappears from list box 2. How do I do this?
Thank you,
Question by:aej1973
    LVL 40

    Accepted Solution

    If you want this to all occur on the client side without multiple trips to the server (where PHP code resides), then this is purely a JavaScript question.

    PHP only executes in response to requests from a user. It is not interacting with the webpage directly.

    Unless you are using an AJAX framework to support a synthetic event driven link between the client and the server, all the user interface stuff happens solely on the client and can only be controlled by JavaScript.

    Author Comment

    Interesting, thank you.
    LVL 4

    Assisted Solution


    just for your help here is the JS Code I found from and use it on many application .....

    <form name=manMod>
    <p><input type="button" name="add" value=">>" onclick="mover
    <p><input type="button" name="remove" value="<<" onclick="mover

    Here is the function...


    function mover(move){

          if(move == 'remove')
                for(x = 0;x<(document.manMod.inBox.length);x++)
                                  options[options.length] = new
                            document.manMod.inBox.options[x] = null;
                            x = -1;
          if(move == 'add')
                for(x = 0;x<(document.manMod.outBox.length);x++)
                                  options[options.length] = new
                            document.manMod.outBox.options[x] =
                            x = -1;
          return true;

    <select name=outBox multiple>

    <select name=inBox multiple>



    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now