How to Move values of one list box to another in form module in Drupal and reverse of it? The values of Listbox are coming from Database

3 Answers 3


Just fiddling with JS should not be enough. Assuming you've built your form using FAPI, it should not accept your form result, as the backend does not know about this options.

You need to make sure Drupal is accepting the options you changed with JS. Please have a look at this discussion at d.o. . You have more than one option to solve this. Either make an AJAX call back rebuild the lists including the changed options. You could also change the options with JS only (as suggested in the other answers) and run your own validation handler to accept the options.

function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == "YOUR_FORM_ID") {
        /*Copy options from one element to another*/
        $form['LIST_BOX_2']['#options'] = $form['LIST_BOX_1']['#options'];
        /*Reverse options in the second element*/
        $form['LIST_BOX_2']['#options'] = array_reverse($form['LIST_BOX_2']['#options']);
  • I want to move selected elements from one listbox to another on button click(Buttons would be >> and << between 2 listboxes)
    – Dharmender
    May 7, 2012 at 6:32
  • You should use javascript then. It is a purely javascript question and it has nothing to do with Drupal then. May 7, 2012 at 6:44
  • Where to write javascript in Module?
    – Dharmender
    May 7, 2012 at 6:55
  • You have to call drupal_add_js() function, check drupal API for detail info.. Jul 9, 2012 at 12:56

Check here for javascript: http://devblog.jasonhuck.com/2008/03/08/combo-select-boxes-in-jquery/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.