Php Flow » CSS, Jquery, Php

Add/Remove Selected Element from MultiSelect

Hi, now we are discussing how to move element between two multi select. First we will create two multi select element.

  1. <form name=“Example” id=“Example” action=“ ” method=“post” onsubmit=“javascript:test();”>  
  2. <table border=“0″ cellpadding=“3″ cellspacing=“0″>  
  3.     <tr>  
  4.         <td>  
  5.             <select id =“Features” name=“Features[]“ multiple=“multiple”>  
  6.                 <option value=“2″>Row 2</option>  
  7.                 <option value=“4″>Row 4</option>  
  8.                 <option value=“5″>Row 5</option>  
  9.                 <option value=“6″>Row 6</option>  
  10.                 <option value=“7″>Row 7</option>  
  11.                 <option value=“8″>Row 8</option>  
  12.                 <option value=“9″>Row 9</option>  
  13.             </select>  
  14.         </td>  
  15.         <td align=“center” valign=“middle”>  
  16.             <input type=“Button” value=“Add >>” style=“width:100px” id=“add”/>  
  17.     
  18.      
  19.   
  20.               
  21.   
  22.             <input type=“Button” value=“<< Remove” style=“width:100px” id=“remove”/>  
  23.      
  24.         </td>  
  25.         <td>  
  26.             <select name=“FeatureCodes[]“ size=“9″ id=“FeatureCodes” multiple=“multiple”>  
  27.                 <option value=“1″>Row 1</option>  
  28.                 <option value=“3″>Row 3</option>  
  29.             </select>  
  30.      
  31.         </td>  
  32.     
  33. <td><input type=“text” name=“tt” value=“55″/></td>  
  34.     </tr>  
  35.  <input type=“submit” name=“submit” value=“submit”/>  
  36. </table>  
  37.   
  38. </form>  
  39.   
  40.   
  41. <script>  
  42.   
  43. $().ready(function() {  
  44.    $(‘#add’).click(function() {  
  45.     return !$(‘#all_artist option:selected’).remove().appendTo(‘#selected_atrist’);  
  46.    });  
  47.    $(‘#remove’).click(function() {  
  48.     return !$(‘#selected_atrist option:selected’).remove().appendTo(‘#all_artist’);  
  49.    });  
  50.     
  51.    
  52.   });  
  53.    
  54.   
  55. function selectall()  
  56. {  
  57. $(‘#selected_atrist’).find(‘option’).each(function() {  
  58.    $(this).attr(‘selected’‘selected’);  
  59.   });  
  60. }  
  61. </script>  

View

moving element multiselect

Did you enjoy this article? Share it!

About the Author:

Hi, This is Parvez Alam from India. I am software developer with 4 years’ experience in web development. I have submitted articles on PHP, Mysql, Magento,CSS, HTML, jQuery, web designing and social API. You can subscribe to my blog via RSS/Twitter/Google plus and Facebook.

Random Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>