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,
Step 1: We will create two element and added button between them.
<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'); }); } });
Please feel free to send queries to me using below comment section.
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
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
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More