Add and Remove List item using javascript :
It is a very usefull plugin for those who want to add and remove list item from one list to another list or who want to switch item from one div to another div. here you will get two buttons which will functioning differently to each other. It is a very help data list for sorting.
When you click on add button this will add selected item from one list to another list. You can add multiple list item on one click from the selection div .
If you click on remove button button this will remove all item from the storage div or list on click.
You are use this plugin to sort your dynamic data and sort your dynamic data list. This will also usefull to migrate data from one list to another list.
It is very simple on fronted to integrate.
How to use it:
Create a html structure for datalist : first of all we will create a html structure in this regards to use it with dynamic data or static array list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <table border="0" cellpadding="0" cellspacing="15"> <tr> <td id="location"><select name="Location" id="loc" multiple="multiple" required size="9"> <option value="OPERATIONS">Operations</option> <option value="CCC">Contact Center</option> <option value="QA">QA Department</option> <option value="DS">DeSoto</option> <option value="PS">Palma Sola</option> <option value="LWR">Lakewood Ranch</option> <option value="NR">North River</option> <option value="SDL">SDL</option> <option value="FSC">FSC</option> </select></td> <td><button id="add" type="button">ADD ALL</button> <button id="rem" type="button">REMOVE ALL</button></td> <td><textarea id="selected" rows="10" readonly></textarea></td> </tr> </table> |
Style for the structure: after creating html structure we will define some style to make it more effective for view.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | table { width: 500px; } select { border: 1px solid #f2f2f2; color: #9E9E9E; padding: 10px; margin-right: 10px; } select option { padding: 3px 10px; background: none; transition: all 0.5s ease; cursor: pointer; } select option:hover { background: #fafafa; } button { border: none; outline: none; padding: 8px 15px; border-radius: 25px; font-size: 14px; color: #fff; opacity: 1; display: block; transition: all 0.5s ease; width: 150px; margin-bottom: 10px; cursor-pointer; } button:hover { opacity: 0.8; } #add { background: #8BC34A; } #rem { background: #FF5722; } textarea { border: 1px solid #f2f2f2; color: #9E9E9E; padding: 10px 15px; margin-left: 10px; line-height: 20px; } |
Adding javascript code to operate it: Add a jquery (any version you can use), we will use a jquery version as a library to use it. After that respectably we have to use javascript code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | $(document).on('change', '#reporttype', function() { var value = $(this).val(); //var checklistreport = $("#checklistreport"); //var locationreport = $("#locationreport"); var location = $("#location"); var employeelist = $("#employeelist"); var chosendates = $("#chosendates"); var formattype = $("#formattype"); var submitbtn = $("#submitbtn"); if (value == "checklistreports") { //checklistreport.show(); //locationreport.hide(); location.show(); employeelist.show(); chosendates.show(); formattype.show(); submitbtn.show(); } else if (value == "locationreports") { //checklistreport.hide(); //locationreport.show(); location.show(); employeelist.hide(); chosendates.show(); formattype.show(); submitbtn.show(); } else { //checklistreport.hide(); //locationreport.hide(); location.hide(); employeelist.hide(); chosendates.hide(); formattype.hide(); submitbtn.hide(); } }); var opts = document.querySelectorAll('#loc option'); document.getElementById('add').addEventListener('click', function() { for (var i = 0; i < opts.length; i++) { opts[i].selected = true; } reflectChange(); }); document.getElementById('rem').addEventListener('click', function() { for (var i = 0; i < opts.length; i++) { opts[i].selected = false; } reflectChange(); }); document.getElementById('loc').addEventListener('change', reflectChange); function reflectChange() { document.getElementById('selected').value = ''; for (var i = 0; i < opts.length; i++) { if (opts[i].selected) document.getElementById('selected').value += opts[i].text + '\n'; } } // End JS for Showing Chosen Locations in textarea // JS for Showing Chosen Associates in textarea var opts1 = document.querySelectorAll('#EmployeeName option'); document.getElementById('add1').addEventListener('click', function() { for (var i = 0; i < opts1.length; i++) { opts1[i].selected = true; } reflectChange1(); }); document.getElementById('rem1').addEventListener('click', function() { for (var i = 0; i < opts1.length; i++) { opts1[i].selected = false; } reflectChange1(); }); document.getElementById('EmployeeName').addEventListener('change', reflectChange1); function reflectChange1() { document.getElementById('selected1').value = ''; for (var i = 0; i < opts1.length; i++) { if (opts1[i].selected) document.getElementById('selected1').value += opts1[i].text + '\n'; } } |
Generally I do not read article on blogs, but I wish to say that this
write-up very forced me to take a look at and do so!
Your writing style has been surprised me. Thanks, very nice article.
When someone writes an post he/she keeps the thought of a user in his/her brain that how a user can know it.
Therefore that’s why this post is outstdanding. Thanks!
What a stuff of un-ambiguity and preserveness of precious knowledge regarding unexpected
feelings.
Hi there, this weekend is pleasant in support of me, because this time i am reading
this wonderful educational piece of writing here at my house.
Saved as a favorite, I like your site!
WOW just what I was searching for. Came here by searching
for google
Wow because this is extremely good work! Congrats and keep it up
If some one wants to be updated with latest technologies after that he must be pay a visit this website and be up
to date every day.
Thanks
It is a really great site!A lot of helpful info and handy tips, bless you =)
Keep on working, great job!
Thanks you very much.
I feel this is among the such a lot vital info for me.
And i’m happy reading your article. However should statement on some basic things, The
website taste is ideal, the articles is in reality nice : D.
Excellent job, cheers
Thanks Mona 🙂
Excellent post. I am dealing with many of these issues as
well..
bookmarked!!, I like your website!
Thanks alot Anch 🙂
It’s not my first time to go to see this web site, i am visiting this web site dailly and obtain nice facts from here daily.
Cool do it .. i will love it