Jquery

Add/Remove Selected Element from MultiSelect

In this tutorial I will provide you script that will use to swapping element between two multi select. This is very common functionality in web development.Multi select is very useful when you are selecting multiple element. Its same as select you can transform normal select to multi using multiple="true" property into normal select. We are using jQuery to move element from one select to another same for reverse.

Checkout other tutorial of jQuery,

Simple Example move Element Between two Multi Select Using jQuery

Step 1: We will create two element and added button between them.

Related Post
<div class="row text-center">


<div class="col-xs-4">
            <select class="form-control" id="features" name="Features[]" multiple="multiple" style="height:200px;">


<option value="2">Row 2</option>  


<option value="4">Row 4</option>  


<option value="5">Row 5</option>  


<option value="6">Row 6</option>  


<option value="7">Row 7</option>  


<option value="8">Row 8</option>  


<option value="9">Row 9</option> 


</select>
</div>




<div class="col-xs-2">


<div class="input-group">
                <button type="button" value="" class="btn btn-xs btn-primary" id="add">Add >></button>
</div>




<div class="input-group" style="padding-top:10px;">
    <button type="button" value="" class="btn btn-xs btn-danger" id="remove"><< Remove</button> 
</div>


</div>




<div class="col-xs-4">
            <select class="form-control" name="FeatureCodes[]" size="9" id="selected_features" multiple="multiple" style="height:200px;">


<option value="1">Row 1</option>  


<option value="3">Row 3</option>


</select>
</div>


</div>


Step 2 : We will add jQuery code which is used for move element between them.

$(document).ready(function(){
   $('#add').click(function() {  
    return !$('#features option:selected')
.remove().appendTo('#selected_features');  
   });  
   $('#remove').click(function() {  
    return !$('#selected_features option:selected')
.remove().appendTo('#features');  
   });  
    
function selectall()  {  
$('#selected_features').find('option').each(function() {  
   $(this).attr('selected', 'selected');  
  });  
}  
});  

Result View

Demo & Download Source Code

Please feel free to send queries to me using below comment section.

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More

3 months ago

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

9 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

9 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

9 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

10 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

10 months ago

Categories